LeetCode#
Companion notebook for the video Benchmarking Local AI on Android with PythonHere and Pydantic Evals.
Generate Python solutions on Android using newfacade/LeetCodeDataset, then run the dataset’s tests locally with Pydantic Evals.
Connect and configure#
# %pip install pydantic-evals datasets
%load_ext pythonhere
%connect-there
We use Qwen2.5-Coder-3B-Instruct with greedy decoding (top_k=1), seed 42,
and a 1,000-token answer limit. %there put copies the run name and settings
to the device.
LIMIT=None selects the full test split; set it to 3 for a short run.
Reuse RUN_NAME to resume, or choose a new name when changing settings or
selected cases. REVISION pins the dataset version.
import os
RUN_NAME = "leetcode-qwen-greedy-full-001"
LIMIT = None # All cases.
REVISION = "215604aeed660029df7de2fea5a4d7b6ed476a08"
settings = {
"model_repo": "litert-community/Qwen2.5-Coder-3B-Instruct",
"model_file": "Qwen2.5_Coder_3B_It.litertlm",
"sampler": {"temperature": 1.0, "top_p": 1.0, "top_k": 1, "seed": 42},
"max_output_tokens": 1000,
"dataset_revision": REVISION,
}
hf_token = os.environ.get("HF_TOKEN")
%there put RUN_NAME
%there put settings
%there put hf_token
Download the model#
%%there --worker
from ml_here import download_hf_model, require_model
try:
model = require_model(settings["model_repo"], settings["model_file"])
except FileNotFoundError:
def report_progress(value):
if value.percent is not None:
print(f"\rDownloading: {value.percent:.1f}%", end="", flush=True)
model = download_hf_model(
repo_id=settings["model_repo"],
filename=settings["model_file"],
token=hf_token,
progress=report_progress,
)
print(model)
/storage/emulated/0/Android/data/me.herethere.pythonhere_dev/files/models/litert-community/Qwen2.5-Coder-3B-Instruct/Qwen2.5_Coder_3B_It.litertlm
Load dataset and build prompts#
We send each problem’s original query to the model. Tests stay local and
are used only for scoring. Inspect one prompt and its tests below.
from datasets import load_dataset
from pprint import pprint as pp
rows = load_dataset("newfacade/LeetCodeDataset", revision=REVISION, split="test")
if LIMIT is not None:
rows = rows.select(range(LIMIT))
problems = [dict(row) for row in rows]
assert problems, "No cases selected"
assert len({p["task_id"] for p in problems}) == len(problems)
pp(f"Selected {len(problems)} cases")
'Selected 228 cases'
print(problems[0]["query"])
You are an expert Python programmer. You will be given a question (problem specification) and will generate a correct Python program that matches the specification and passes all tests.
### Question:
You are given an integer n and a 2D integer array queries.
There are n cities numbered from 0 to n - 1. Initially, there is a unidirectional road from city i to city i + 1 for all 0 <= i < n - 1.
queries[i] = [ui, vi] represents the addition of a new unidirectional road from city ui to city vi. After each query, you need to find the length of the shortest path from city 0 to city n - 1.
Return an array answer where for each i in the range [0, queries.length - 1], answer[i] is the length of the shortest path from city 0 to city n - 1 after processing the first i + 1 queries.
Example 1:
Input: n = 5, queries = [[2,4],[0,2],[0,4]]
Output: [3,2,1]
Explanation:
After the addition of the road from 2 to 4, the length of the shortest path from 0 to 4 is 3.
After the addition of the road from 0 to 2, the length of the shortest path from 0 to 4 is 2.
After the addition of the road from 0 to 4, the length of the shortest path from 0 to 4 is 1.
Example 2:
Input: n = 4, queries = [[0,3],[0,2]]
Output: [1,1]
Explanation:
After the addition of the road from 0 to 3, the length of the shortest path from 0 to 3 is 1.
After the addition of the road from 0 to 2, the length of the shortest path remains 1.
Constraints:
3 <= n <= 500
1 <= queries.length <= 500
queries[i].length == 2
0 <= queries[i][0] < queries[i][1] < n
1 < queries[i][1] - queries[i][0]
There are no repeated roads among the queries.
### Format: You will use the following starter code to write the solution to the problem and enclose your code within delimiters.
```python
class Solution:
def shortestDistanceAfterQueries(self, n: int, queries: List[List[int]]) -> List[int]:
```
### Answer: (use the provided format with backticks)
print(problems[0]["test"])
def check(candidate):
assert candidate(n = 7,queries = [[0, 5], [1, 6], [2, 4]]) == [2, 2, 2]
assert candidate(n = 8,queries = [[1, 5], [2, 6], [3, 7], [0, 4], [0, 6], [0, 7]]) == [4, 4, 4, 4, 2, 1]
assert candidate(n = 6,queries = [[1, 3], [2, 5], [0, 3]]) == [4, 3, 3]
assert candidate(n = 8,queries = [[0, 6], [1, 7], [2, 5], [3, 4]]) == [2, 2, 2, 2]
assert candidate(n = 7,queries = [[1, 5], [2, 6], [3, 5]]) == [3, 3, 3]
assert candidate(n = 6,queries = [[1, 3], [2, 4], [0, 3]]) == [4, 4, 3]
assert candidate(n = 6,queries = [[1, 3], [2, 5], [0, 1], [3, 4]]) == [4, 3, 3, 3]
assert candidate(n = 5,queries = [[2, 4], [0, 2], [0, 4]]) == [3, 2, 1]
assert candidate(n = 4,queries = [[0, 3], [0, 2]]) == [1, 1]
assert candidate(n = 7,queries = [[1, 4], [2, 6], [3, 5], [0, 3], [0, 5]]) == [4, 3, 3, 3, 2]
assert candidate(n = 50,queries = [[0, 49], [0, 48], [1, 47], [2, 46], [3, 45], [4, 44], [5, 43], [6, 42], [7, 41], [8, 40], [9, 39], [10, 38], [11, 37], [12, 36], [13, 35], [14, 34], [15, 33], [16, 32], [17, 31], [18, 30], [19, 29], [20, 28], [21, 27], [22, 26], [23, 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]
assert candidate(n = 50,queries = [[0, 25], [0, 30], [0, 35], [0, 40], [0, 45], [5, 15], [5, 20], [5, 25], [5, 30], [5, 35], [5, 40], [5, 45], [10, 20], [10, 25], [10, 30], [10, 35], [10, 40], [10, 45], [15, 25], [15, 30], [15, 35], [15, 40], [15, 45], [20, 30], [20, 35], [20, 40], [20, 45], [25, 35], [25, 40], [25, 45], [30, 40], [30, 45], [35, 45]]) == [25, 20, 15, 10, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]
assert candidate(n = 45,queries = [[0, 18], [5, 28], [10, 34], [15, 39], [20, 41], [25, 43], [30, 44], [35, 42], [1, 19], [6, 30], [11, 35], [16, 40], [21, 42], [26, 36], [31, 37]]) == [27, 22, 21, 21, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]
assert candidate(n = 15,queries = [[0, 10], [1, 8], [2, 12], [3, 7], [4, 9], [5, 11], [6, 13], [7, 14]]) == [5, 5, 5, 5, 5, 5, 5, 5]
assert candidate(n = 12,queries = [[0, 5], [0, 11], [1, 10], [2, 8], [3, 9], [4, 7], [5, 6]]) == [7, 1, 1, 1, 1, 1, 1]
assert candidate(n = 20,queries = [[0, 19], [0, 10], [1, 18], [2, 17], [3, 16], [4, 15], [5, 14], [6, 13], [7, 12], [8, 9]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
assert candidate(n = 10,queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5], [0, 7], [2, 5], [1, 4]]) == [1, 1, 1, 1, 1, 1, 1, 1]
assert candidate(n = 10,queries = [[0, 5], [1, 4], [2, 6], [3, 7], [8, 9]]) == [5, 5, 5, 5, 5]
assert candidate(n = 50,queries = [[0, 49], [1, 48], [2, 47], [3, 46], [4, 45], [5, 44], [6, 43], [7, 42], [8, 41], [9, 40], [10, 39], [11, 38], [12, 37], [13, 36], [14, 35], [15, 34], [16, 33], [17, 32], [18, 31], [19, 30], [0, 47], [2, 45], [4, 43], [6, 41], [8, 39], [10, 38], [12, 37], [14, 36], [16, 35], [18, 34], [20, 33], [22, 32], [24, 31], [26, 30], [28, 29]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
assert candidate(n = 20,queries = [[0, 10], [1, 15], [2, 19], [3, 18], [4, 17], [5, 16], [6, 15], [7, 14], [8, 13], [9, 12], [10, 19], [11, 18], [12, 17], [13, 16], [14, 15]]) == [10, 6, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2]
assert candidate(n = 12,queries = [[0, 11], [0, 6], [1, 10], [2, 9], [3, 8], [4, 7], [5, 6]]) == [1, 1, 1, 1, 1, 1, 1]
assert candidate(n = 50,queries = [[0, 49], [1, 48], [2, 47], [3, 46], [4, 45], [5, 44], [6, 43], [7, 42], [8, 41], [9, 40], [10, 39], [11, 38], [12, 37], [13, 36], [14, 35], [15, 34], [16, 33], [17, 32], [18, 31], [19, 30], [20, 29], [21, 28], [22, 27], [23, 26], [24, 25], [25, 24], [26, 23], [27, 22], [28, 21], [29, 20], [30, 19], [31, 18], [32, 17], [33, 16], [34, 15], [35, 14], [36, 13], [37, 12], [38, 11], [39, 10], [40, 9], [41, 8], [42, 7], [43, 6], [44, 5], [45, 4], [46, 3], [47, 2], [48, 1]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
assert candidate(n = 30,queries = [[0, 10], [0, 15], [0, 20], [5, 25], [5, 29], [10, 19], [10, 24], [15, 23], [15, 28], [20, 22], [20, 27], [25, 26]]) == [20, 15, 10, 10, 6, 6, 6, 6, 3, 3, 3, 3]
assert candidate(n = 100,queries = [[0, 99], [0, 98], [1, 97], [2, 96], [3, 95], [4, 94], [5, 93], [6, 92], [7, 91], [8, 90], [9, 89], [10, 88], [11, 87], [12, 86], [13, 85], [14, 84], [15, 83], [16, 82], [17, 81], [18, 80], [19, 79], [20, 78], [21, 77], [22, 76], [23, 75], [24, 74], [25, 73], [26, 72], [27, 71], [28, 70], [29, 69], [30, 68], [31, 67], [32, 66], [33, 65], [34, 64], [35, 63], [36, 62], [37, 61], [38, 60], [39, 59], [40, 58], [41, 57], [42, 56], [43, 55], [44, 54], [45, 53], [46, 52], [47, 51], [48, 50]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
assert candidate(n = 30,queries = [[0, 20], [1, 21], [2, 22], [3, 23], [4, 24], [5, 25], [6, 26], [7, 27], [8, 28], [9, 29], [10, 25], [11, 26], [12, 27], [13, 28], [14, 29], [15, 28], [16, 29], [0, 15], [2, 21], [4, 23], [6, 25], [8, 27]]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 3, 3, 3, 3, 3]
assert candidate(n = 15,queries = [[0, 10], [1, 11], [2, 12], [3, 13], [4, 14], [5, 13], [6, 14], [0, 9], [2, 11], [4, 12]]) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]
assert candidate(n = 15,queries = [[0, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9], [6, 8], [0, 12], [1, 10], [2, 9], [3, 8], [4, 7], [5, 6]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
assert candidate(n = 20,queries = [[0, 19], [1, 18], [2, 17], [3, 16], [4, 15], [5, 14], [6, 13], [7, 12], [8, 11], [9, 10], [0, 17], [2, 15], [4, 13], [6, 11], [8, 9]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
assert candidate(n = 12,queries = [[0, 6], [2, 8], [3, 9], [5, 10], [7, 11], [1, 5]]) == [6, 6, 6, 6, 3, 3]
assert candidate(n = 10,queries = [[0, 9], [1, 8], [2, 7], [3, 6], [4, 5]]) == [1, 1, 1, 1, 1]
assert candidate(n = 40,queries = [[0, 15], [5, 25], [10, 30], [15, 35], [20, 37], [25, 38], [30, 39], [1, 16], [6, 26], [11, 31], [16, 36], [21, 32], [26, 33]]) == [25, 20, 20, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]
assert candidate(n = 10,queries = [[0, 7], [2, 9], [3, 6], [0, 5], [4, 8]]) == [3, 3, 3, 3, 3]
assert candidate(n = 15,queries = [[0, 14], [1, 10], [2, 8], [3, 9], [4, 11], [5, 12], [6, 13]]) == [1, 1, 1, 1, 1, 1, 1]
assert candidate(n = 20,queries = [[0, 10], [1, 11], [2, 12], [3, 13], [4, 14], [5, 15], [6, 16], [7, 17], [8, 18], [9, 19], [0, 15], [1, 16]]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 5, 5]
assert candidate(n = 12,queries = [[0, 2], [0, 4], [0, 6], [0, 8], [0, 10], [1, 3], [1, 5], [1, 7], [1, 9], [1, 11]]) == [10, 8, 6, 4, 2, 2, 2, 2, 2, 2]
assert candidate(n = 15,queries = [[0, 7], [1, 9], [2, 11], [3, 10], [4, 12], [5, 13], [6, 14]]) == [8, 7, 6, 6, 6, 6, 6]
assert candidate(n = 10,queries = [[0, 5], [1, 7], [3, 8], [2, 6], [0, 9]]) == [5, 4, 4, 4, 1]
assert candidate(n = 15,queries = [[0, 14], [0, 7], [1, 12], [2, 11], [3, 10], [4, 9], [5, 8], [6, 7]]) == [1, 1, 1, 1, 1, 1, 1, 1]
assert candidate(n = 30,queries = [[0, 25], [1, 26], [2, 27], [3, 28], [4, 29], [5, 15], [6, 16], [7, 17], [8, 18], [9, 19], [10, 20], [11, 21], [12, 22], [13, 23], [14, 24]]) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]
assert candidate(n = 10,queries = [[0, 5], [1, 6], [2, 7], [3, 8], [4, 9], [0, 7], [2, 9]]) == [5, 5, 5, 5, 5, 3, 3]
assert candidate(n = 25,queries = [[0, 15], [1, 16], [2, 17], [3, 18], [4, 19], [5, 20], [6, 21], [7, 22], [8, 23], [9, 24], [10, 20], [11, 21], [12, 22], [13, 23], [14, 24]]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
assert candidate(n = 30,queries = [[0, 12], [5, 18], [10, 22], [15, 24], [20, 28], [25, 29], [1, 13], [6, 19], [11, 23], [16, 25]]) == [18, 17, 17, 10, 10, 7, 7, 7, 7, 7]
assert candidate(n = 10,queries = [[0, 4], [0, 5], [0, 8], [0, 6], [1, 3], [2, 7], [3, 9], [4, 8]]) == [6, 5, 2, 2, 2, 2, 2, 2]
assert candidate(n = 30,queries = [[0, 29], [1, 28], [2, 27], [3, 26], [4, 25], [5, 24], [6, 23], [7, 22], [8, 21], [9, 20], [10, 19], [11, 18], [12, 17], [13, 16], [14, 15], [15, 14], [16, 13], [17, 12], [18, 11], [19, 10], [20, 9], [21, 8], [22, 7], [23, 6], [24, 5], [25, 4], [26, 3], [27, 2], [28, 1]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
assert candidate(n = 15,queries = [[0, 14], [1, 13], [2, 12], [3, 11], [4, 10], [5, 9], [6, 8]]) == [1, 1, 1, 1, 1, 1, 1]
assert candidate(n = 10,queries = [[0, 9], [0, 5], [1, 8], [2, 4], [3, 7]]) == [1, 1, 1, 1, 1]
assert candidate(n = 40,queries = [[0, 10], [0, 15], [0, 20], [0, 25], [0, 30], [5, 15], [5, 20], [5, 25], [5, 30], [10, 20], [10, 25], [10, 30], [15, 25], [15, 30], [20, 30]]) == [30, 25, 20, 15, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
assert candidate(n = 40,queries = [[0, 35], [1, 36], [2, 37], [3, 38], [4, 39], [5, 25], [6, 26], [7, 27], [8, 28], [9, 29], [10, 30], [11, 31], [12, 32], [13, 33], [14, 34], [15, 20], [16, 21], [17, 22], [18, 23], [19, 24]]) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]
assert candidate(n = 50,queries = [[0, 45], [1, 46], [2, 47], [3, 48], [4, 49], [5, 35], [6, 36], [7, 37], [8, 38], [9, 39], [10, 40], [11, 41], [12, 42], [13, 43], [14, 44], [15, 30], [16, 31], [17, 32], [18, 33], [19, 34], [20, 25], [21, 26], [22, 27], [23, 28], [24, 29]]) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]
assert candidate(n = 15,queries = [[0, 14], [1, 12], [2, 13], [3, 11], [4, 9], [5, 10], [6, 8], [7, 10], [8, 13], [9, 14]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
assert candidate(n = 10,queries = [[0, 5], [5, 9], [2, 6], [1, 8], [3, 7]]) == [5, 2, 2, 2, 2]
assert candidate(n = 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]
assert candidate(n = 20,queries = [[0, 10], [1, 11], [2, 12], [3, 13], [4, 14], [5, 15], [6, 16], [7, 17], [8, 18], [9, 19], [0, 9], [2, 11], [4, 13], [6, 15], [8, 17]]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 2, 2, 2, 2, 2]
assert candidate(n = 25,queries = [[0, 24], [0, 23], [0, 22], [1, 21], [2, 20], [3, 19], [4, 18], [5, 17], [6, 16], [7, 15], [8, 14], [9, 13], [10, 12]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
assert candidate(n = 15,queries = [[0, 4], [1, 8], [2, 10], [3, 11], [4, 12], [5, 13], [6, 14], [0, 13], [1, 14]]) == [11, 8, 7, 7, 4, 4, 4, 2, 2]
assert candidate(n = 20,queries = [[0, 15], [5, 18], [10, 19], [1, 12], [3, 17], [7, 16], [9, 14], [2, 13]]) == [5, 5, 5, 5, 5, 5, 5, 5]
assert candidate(n = 10,queries = [[0, 2], [1, 3], [2, 9], [3, 5], [4, 8], [5, 7], [6, 9], [7, 8]]) == [8, 8, 2, 2, 2, 2, 2, 2]
assert candidate(n = 30,queries = [[0, 29], [1, 28], [2, 27], [3, 26], [4, 25], [5, 24], [6, 23], [7, 22], [8, 21], [9, 20], [10, 19], [11, 18], [12, 17], [13, 16], [14, 15], [0, 27], [2, 25], [4, 23], [6, 21], [8, 19], [10, 18], [12, 17], [14, 16]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
assert candidate(n = 25,queries = [[0, 24], [1, 23], [2, 22], [3, 21], [4, 20], [5, 19], [6, 18], [7, 17], [8, 16], [9, 15], [10, 14], [11, 13], [12, 12], [13, 11], [14, 10], [15, 9], [16, 8], [17, 7], [18, 6], [19, 5], [20, 4], [21, 3], [22, 2], [23, 1]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
assert candidate(n = 25,queries = [[0, 15], [1, 8], [2, 10], [3, 12], [4, 14], [5, 16], [6, 18], [7, 20], [8, 22], [9, 24], [10, 17], [11, 19], [12, 21], [13, 23]]) == [10, 10, 10, 10, 10, 10, 10, 10, 5, 4, 4, 4, 4, 4]
assert candidate(n = 18,queries = [[0, 17], [0, 9], [1, 16], [2, 15], [3, 14], [4, 13], [5, 12], [6, 11], [7, 10], [8, 9]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
assert candidate(n = 35,queries = [[0, 13], [5, 20], [10, 24], [15, 28], [20, 32], [25, 34], [30, 33], [1, 14], [6, 21], [11, 25], [16, 29], [21, 31]]) == [22, 20, 20, 10, 9, 9, 8, 8, 8, 8, 8, 8]
assert candidate(n = 15,queries = [[0, 14], [0, 13], [0, 12], [1, 11], [2, 10], [3, 9], [4, 8], [5, 7]]) == [1, 1, 1, 1, 1, 1, 1, 1]
assert candidate(n = 25,queries = [[0, 10], [5, 20], [10, 22], [15, 23], [20, 24], [2, 12], [7, 17], [12, 21]]) == [15, 10, 4, 4, 4, 4, 4, 4]
assert candidate(n = 20,queries = [[0, 19], [0, 18], [1, 17], [2, 16], [3, 15], [4, 14], [5, 13], [6, 12], [7, 11], [8, 10]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
assert candidate(n = 20,queries = [[0, 15], [1, 16], [2, 17], [3, 18], [4, 19], [5, 13], [6, 14], [7, 12], [8, 11], [9, 10]]) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5]
assert candidate(n = 25,queries = [[0, 15], [1, 16], [2, 17], [3, 18], [4, 19], [5, 20], [6, 21], [7, 22], [8, 23], [9, 24], [10, 18], [11, 19], [12, 20], [13, 21], [14, 22], [0, 8], [2, 16], [4, 18], [6, 20], [8, 22]]) == [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 3, 3, 3, 3, 3]
assert candidate(n = 50,queries = [[0, 20], [5, 30], [10, 36], [15, 40], [20, 44], [25, 47], [30, 48], [35, 49], [40, 46], [1, 21], [6, 31], [11, 37], [16, 41], [21, 43], [26, 38], [31, 39], [36, 45]]) == [30, 25, 24, 24, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]
assert candidate(n = 25,queries = [[0, 24], [0, 13], [1, 23], [2, 22], [3, 21], [4, 20], [5, 19], [6, 18], [7, 17], [8, 16], [9, 15], [10, 14], [11, 12]]) == [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
assert candidate(n = 20,queries = [[0, 10], [1, 5], [2, 8], [3, 7], [4, 6], [5, 15], [6, 12], [7, 18], [8, 16], [9, 19]]) == [10, 10, 10, 10, 10, 7, 7, 6, 6, 5]
tasks = [
{"id": p["task_id"], "prompt": p["query"],
"metadata": {"difficulty": p["difficulty"].lower()}}
for p in problems
]
Start/resume answers generation run#
TaskRunner saves answers on the device and continues after the notebook
disconnects. Starting the same named run processes unfinished tasks. The engine
is shared across tasks, with a fresh conversation for each solution.
%there put tasks
%%there
from tasks_here import TaskRunner, TaskRunExistsError
try:
leetcode_runner = TaskRunner.create(RUN_NAME, max_attempts=3, metadata=settings)
except TaskRunExistsError:
leetcode_runner = TaskRunner.open(RUN_NAME)
existing = [r["task"] for r in leetcode_runner.results()]
if not existing:
leetcode_runner.add(tasks)
%%there
import litert_lm
from ml_here import require_model
def leetcode_setup():
global leetcode_engine
if globals().get("leetcode_engine") is not None:
raise RuntimeError("Close previous leetcode_engine using the last cell before resuming")
leetcode_engine = litert_lm.Engine(
require_model(settings["model_repo"], settings["model_file"]),
backend=litert_lm.Backend.GPU(), enable_benchmark=True,
)
return leetcode_engine
def leetcode_execute(task, engine):
with engine.create_conversation(
sampler_config=litert_lm.SamplerConfig(**settings["sampler"]),
max_output_tokens=settings["max_output_tokens"],
) as conversation:
response = conversation.send_message(task["prompt"])
try:
info = conversation.get_benchmark_info()
benchmark = {k: getattr(info, k) for k in (
"init_time_in_second", "time_to_first_token_in_second",
"last_prefill_token_count", "last_prefill_tokens_per_second",
"last_decode_token_count", "last_decode_tokens_per_second",
)}
benchmark_error = None
except Exception as exc:
benchmark, benchmark_error = None, str(exc)
return {
"output": "".join(b["text"] for b in response["content"] if "text" in b),
"benchmark": benchmark, "benchmark_error": benchmark_error,
}
if not leetcode_runner.is_running():
leetcode_runner.start(leetcode_execute, setup=leetcode_setup)
print(leetcode_runner.status())
{'name': 'leetcode-qwen-greedy-full-001', 'state': 'completed', 'total': 228, 'pending': 0, 'running': 0, 'completed': 228, 'failed': 0, 'progress': 1.0, 'current': None, 'pause_requested': False, 'max_attempts': 3, 'exclusive': True, 'created_at': '2026-09-17T21:48:35.563260+00:00', 'updated_at': '2026-10-29T22:54:29.704064+00:00', 'metadata': {}, 'worker_error': None, 'path': '/data/user/0/me.herethere.pythonhere_dev/files/task-runs/leetcode-qwen-greedy-full-001'}
Check progress and fetch the results#
Completed answers can be fetched and scored while generation continues. After reconnecting, rerun the configuration and run-opening cells to retrieve saved answers without starting generation again.
%there get leetcode_runner.status()
{'name': 'leetcode-qwen-greedy-full-001',
'state': 'completed',
'total': 228,
'pending': 0,
'running': 0,
'completed': 228,
'failed': 0,
'progress': 1.0,
'current': None,
'pause_requested': False,
'max_attempts': 3,
'exclusive': True,
'created_at': '2026-09-17T21:48:35.563260+00:00',
'updated_at': '2026-10-29T22:54:29.704064+00:00',
'metadata': {},
'worker_error': None,
'path': '/data/user/0/me.herethere.pythonhere_dev/files/task-runs/leetcode-qwen-greedy-full-001'}
results = %there get leetcode_runner.results()
pp(results[-1])
{'attempt_count': 1,
'attempts': [{'duration': 65.69324554200284,
'error': None,
'finished_at': '2026-09-18T17:05:00.478428+00:00',
'number': 1,
'started_at': '2026-09-18T17:03:54.781012+00:00'}],
'completed_at': '2026-09-18T17:05:00.478464+00:00',
'created_at': '2026-09-17T21:48:35.616171+00:00',
'duration': 65.69324554200284,
'error': None,
'failure_count': 0,
'id': 'minimum-operations-to-make-elements-within-k-subarrays-equal',
'result': {'benchmark': {'init_time_in_second': 35.336318156,
'last_decode_token_count': 126,
'last_decode_tokens_per_second': 3.1213213294337807,
'last_prefill_token_count': 610,
'last_prefill_tokens_per_second': 24.098436172011727,
'time_to_first_token_in_second': 25.63322298775},
'output': '```python\n'
'class Solution:\n'
' def minOperations(self, nums: List[int], x: int, k: '
'int) -> int:\n'
' n = len(nums)\n'
' count = 0\n'
' operations = 0\n'
' \n'
' for i in range(n):\n'
' if nums[i] == x:\n'
' count += 1\n'
' if count == k:\n'
' operations += n - i - 1\n'
' count = 0\n'
' elif count > k:\n'
' operations += n - i - 1\n'
' count = 1\n'
' else:\n'
' count = 0\n'
' \n'
' return operations\n'
'```'},
'result_present': True,
'status': 'done',
'task': {'id': 'minimum-operations-to-make-elements-within-k-subarrays-equal',
'metadata': {'difficulty': 'Hard',
'task_id': 'minimum-operations-to-make-elements-within-k-subarrays-equal'},
'prompt': 'You are an expert Python programmer. You will be given a '
'question (problem specification) and will generate a '
'correct Python program that matches the specification and '
'passes all tests.\n'
'\n'
'### Question:\n'
'You are given an integer array nums and two integers, x '
'and k. You can perform the following operation any number '
'of times (including zero):\n'
'\n'
'Increase or decrease any element of nums by 1.\n'
'\n'
'Return the minimum number of operations needed to have at '
'least k non-overlapping subarrays of size exactly x in '
'nums, where all elements within each subarray are equal.\n'
'\xa0\n'
'Example 1:\n'
'\n'
'Input: nums = [5,-2,1,3,7,3,6,4,-1], x = 3, k = 2\n'
'Output: 8\n'
'Explanation:\n'
'\n'
'Use 3 operations to add 3 to nums[1] and use 2 operations '
'to subtract 2 from nums[3]. The resulting array is [5, 1, '
'1, 1, 7, 3, 6, 4, -1].\n'
'Use 1 operation to add 1 to nums[5] and use 2 operations '
'to subtract 2 from nums[6]. The resulting array is [5, 1, '
'1, 1, 7, 4, 4, 4, -1].\n'
'Now, all elements within each subarray [1, 1, 1] (from '
'indices 1 to 3) and [4, 4, 4] (from indices 5 to 7) are '
'equal. Since 8 total operations were used, 8 is the '
'output.\n'
'\n'
'\n'
'Example 2:\n'
'\n'
'Input: nums = [9,-2,-2,-2,1,5], x = 2, k = 2\n'
'Output: 3\n'
'Explanation:\n'
'\n'
'Use 3 operations to subtract 3 from nums[4]. The '
'resulting array is [9, -2, -2, -2, -2, 5].\n'
'Now, all elements within each subarray [-2, -2] (from '
'indices 1 to 2) and [-2, -2] (from indices 3 to 4) are '
'equal. Since 3 operations were used, 3 is the output.\n'
'\n'
'\n'
'\xa0\n'
'Constraints:\n'
'\n'
'2 <= nums.length <= 105\n'
'-106 <= nums[i] <= 106\n'
'2 <= x <= nums.length\n'
'1 <= k <= 15\n'
'2 <= k * x <= nums.length\n'
'\n'
'\n'
'\n'
'### Format: You will use the following starter code to '
'write the solution to the problem and enclose your code '
'within delimiters.\n'
'```python\n'
'class Solution:\n'
' def minOperations(self, nums: List[int], x: int, k: '
'int) -> int:\n'
' \n'
'```\n'
'\n'
'### Answer: (use the provided format with backticks)\n'},
'total_duration': 65.69324554200284}
Score fetched answers locally#
We build a Pydantic Evals Dataset from completed answers. The custom
LeetCodePass evaluator extracts Python code and runs each solution with its
tests in a local subprocess, with a 10-second timeout. The difficulty summary
separates passes, assertion failures, invalid answers, syntax errors, runtime
errors, and timeouts.
generation_s is TaskRunner’s elapsed time around the final leetcode_execute
call on the device, including conversation setup and cleanup but excluding
engine loading and earlier retries. decode_tokens_s is the decoding speed
reported by LiteRT’s benchmark.
import sys
import json
import re
import subprocess
from dataclasses import dataclass
from pydantic_evals import Case, Dataset, increment_eval_metric
from pydantic_evals.evaluators import Evaluator, EvaluationReason
def extract_python_code(text):
fences = re.findall(r"```([^\n`]*)\n(.*?)```", text, flags=re.DOTALL)
if fences:
if len(fences) != 1 or fences[0][0].strip().lower() not in {"", "python", "py"}:
raise ValueError("Expected one Python code block")
code = fences[0][1].strip()
elif "```" in text:
raise ValueError("Incomplete code block")
else:
code = text.strip()
if not code:
raise ValueError("Empty code")
return code
def execute_problem(problem, code, timeout):
program = "\n".join([
problem["prompt"], code, problem["test"],
f"check({problem['entry_point']})",
])
# Report success only after the complete program and tests return.
harness = f'''
import json
try:
exec(compile({program!r}, "<solution>", "exec"), {{}})
except SyntaxError as exc:
result = {{"outcome": "syntax_error", "error": str(exc)}}
except AssertionError as exc:
result = {{"outcome": "test_failed", "error": "AssertionError: " + str(exc)}}
except BaseException as exc:
result = {{"outcome": "runtime_error", "error": type(exc).__name__ + ": " + str(exc)}}
else:
result = {{"outcome": "passed"}}
print("__TEST_RESULT__" + json.dumps(result))
'''
try:
process = subprocess.run(
[sys.executable, "-I", "-"], input=harness,
text=True, capture_output=True, timeout=timeout,
)
except subprocess.TimeoutExpired:
return {"outcome": "timeout", "error": f"Exceeded {timeout:g} seconds"}
for line in reversed(process.stdout.splitlines()):
if line.startswith("__TEST_RESULT__"):
return json.loads(line[len("__TEST_RESULT__"):])
return {"outcome": "runtime_error", "error": process.stderr.strip() or "Tests did not finish"}
@dataclass
class LeetCodePass(Evaluator):
problems: dict
timeout: float = 10.0
def evaluate(self, ctx):
try:
code = extract_python_code(ctx.output)
except ValueError as exc:
return {
"passed": EvaluationReason(False, str(exc)),
"failure": "invalid",
}
problem = self.problems[ctx.inputs]
result = execute_problem(problem, code, self.timeout)
if result["outcome"] == "passed":
return {"passed": True}
return {
"passed": EvaluationReason(False, result.get("error") or result["outcome"]),
"failure": result["outcome"],
}
from collections import Counter
from pydantic_evals.evaluators import ReportEvaluator, ReportEvaluatorContext
from pydantic_evals.reporting.analyses import TableResult
@dataclass
class LeetCodeSummary(ReportEvaluator):
def evaluate(self, ctx: ReportEvaluatorContext):
categories = ["passed", "test_failed", "invalid", "syntax_error",
"runtime_error", "timeout"]
rows = []
for difficulty in ["all", "easy", "medium", "hard"]:
cases = [c for c in ctx.report.cases
if difficulty == "all" or c.metadata["difficulty"] == difficulty]
if not cases:
continue
counts = Counter()
for case in cases:
if case.assertions["passed"].value:
counts["passed"] += 1
else:
counts[case.labels["failure"].value] += 1
rows.append([difficulty, len(cases),
*[round(100 * counts[name] / len(cases), 1)
for name in categories]])
return TableResult(
title="LeetCode results by difficulty",
columns=["Difficulty", "N", "Passed %", "Assertion %", "Invalid %",
"Syntax %", "Runtime %", "Timeout %"],
rows=rows,
)
problems_by_id = {p["task_id"]: p for p in problems}
completed = {r["id"]: r for r in results if r["status"] == "done"}
for case_id, record in completed.items():
if case_id not in problems_by_id or record["task"]["prompt"] != problems_by_id[case_id]["query"]:
raise ValueError("Fetched tasks differ from selected dataset")
def saved_answer(case_id):
record = completed[case_id]
if record.get("duration") is not None:
increment_eval_metric("generation_s", record["duration"])
benchmark = record["result"].get("benchmark") or {}
speed = benchmark.get("last_decode_tokens_per_second")
if speed is not None:
increment_eval_metric("decode_tokens_s", speed)
return record["result"]["output"]
dataset = Dataset(
name="pythonhere-leetcode",
cases=[Case(name=p["task_id"], inputs=p["task_id"],
metadata={"difficulty": p["difficulty"].lower()})
for p in problems if p["task_id"] in completed],
evaluators=[LeetCodePass(problems_by_id)],
report_evaluators=[LeetCodeSummary()],
)
if not dataset.cases:
raise RuntimeError("No completed answers; check device status/errors")
report = await dataset.evaluate(saved_answer, max_concurrency=1)
# report.print(include_durations=False, include_averages=True, include_reasons=True)
from dataclasses import replace
# Show the first eight cases; LeetCodeSummary covers all scored cases.
preview = replace(report, cases=report.cases[:8])
preview.print(include_durations=False, include_averages=False, include_analyses=True, include_reasons=True)
Evaluation Summary: saved_answer ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Case ID ┃ Labels ┃ Metrics ┃ Assertions ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ shortest-distance-after-road-… │ failure: runtime_error │ generation_s: 120.0 │ passed: ✗ │ │ │ │ decode_tokens_s: 3.08 │ Reason: ValueError: │ │ │ │ │ list.remove(x): x not in list │ │ │ │ │ │ │ │ │ │ │ ├────────────────────────────────┼────────────────────────┼───────────────────────┼───────────────────────────────┤ │ shortest-distance-after-road-… │ failure: test_failed │ generation_s: 229.4 │ passed: ✗ │ │ │ │ decode_tokens_s: 3.15 │ Reason: AssertionError: │ │ │ │ │ │ │ │ │ │ │ ├────────────────────────────────┼────────────────────────┼───────────────────────┼───────────────────────────────┤ │ number-of-subsequences-with-o… │ failure: test_failed │ generation_s: 63.0 │ passed: ✗ │ │ │ │ decode_tokens_s: 3.13 │ Reason: AssertionError: │ │ │ │ │ │ │ │ │ │ │ ├────────────────────────────────┼────────────────────────┼───────────────────────┼───────────────────────────────┤ │ snake-in-matrix │ failure: test_failed │ generation_s: 86.2 │ passed: ✗ │ │ │ │ decode_tokens_s: 3.15 │ Reason: AssertionError: │ │ │ │ │ │ │ │ │ │ │ ├────────────────────────────────┼────────────────────────┼───────────────────────┼───────────────────────────────┤ │ count-the-number-of-good-nodes │ failure: test_failed │ generation_s: 71.9 │ passed: ✗ │ │ │ │ decode_tokens_s: 3.16 │ Reason: AssertionError: │ │ │ │ │ │ │ │ │ │ │ ├────────────────────────────────┼────────────────────────┼───────────────────────┼───────────────────────────────┤ │ find-the-count-of-monotonic-p… │ failure: runtime_error │ generation_s: 72.0 │ passed: ✗ │ │ │ │ decode_tokens_s: 3.17 │ Reason: AttributeError: │ │ │ │ │ 'builtin_function_or_method' │ │ │ │ │ object has no attribute │ │ │ │ │ 'bisect_left' │ │ │ │ │ │ │ │ │ │ │ ├────────────────────────────────┼────────────────────────┼───────────────────────┼───────────────────────────────┤ │ find-the-count-of-monotonic-p… │ failure: test_failed │ generation_s: 95.1 │ passed: ✗ │ │ │ │ decode_tokens_s: 3.15 │ Reason: AssertionError: │ │ │ │ │ │ │ │ │ │ │ ├────────────────────────────────┼────────────────────────┼───────────────────────┼───────────────────────────────┤ │ construct-string-with-minimum… │ failure: runtime_error │ generation_s: 68.2 │ passed: ✗ │ │ │ │ decode_tokens_s: 3.15 │ Reason: IndexError: list │ │ │ │ │ index out of range │ │ │ │ │ │ │ │ │ │ │ └────────────────────────────────┴────────────────────────┴───────────────────────┴───────────────────────────────┘
LeetCode results by difficulty ┏━━━━━━━━━━━━┳━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━┓ ┃ Difficulty ┃ N ┃ Passed % ┃ Assertion % ┃ Invalid % ┃ Syntax % ┃ Runtime % ┃ Timeout % ┃ ┡━━━━━━━━━━━━╇━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━┩ │ all │ 228 │ 10.1 │ 61.8 │ 6.1 │ 5.3 │ 15.4 │ 1.3 │ ├────────────┼─────┼──────────┼─────────────┼───────────┼──────────┼───────────┼───────────┤ │ easy │ 48 │ 31.2 │ 54.2 │ 6.2 │ 4.2 │ 4.2 │ 0.0 │ ├────────────┼─────┼──────────┼─────────────┼───────────┼──────────┼───────────┼───────────┤ │ medium │ 101 │ 5.9 │ 71.3 │ 6.9 │ 3.0 │ 11.9 │ 1.0 │ ├────────────┼─────┼──────────┼─────────────┼───────────┼──────────┼───────────┼───────────┤ │ hard │ 79 │ 2.5 │ 54.4 │ 5.1 │ 8.9 │ 26.6 │ 2.5 │ └────────────┴─────┴──────────┴─────────────┴───────────┴──────────┴───────────┴───────────┘
Show bad answers that are missing class Solution.
from rich.console import Console
from rich.table import Table
from rich.text import Text
weird = [
r["result"]["output"]
for r in results
if r["status"] == "done"
and "class Solution" not in r["result"]["output"]
]
table = Table(title=f"Unexpected outputs ({len(weird)})")
table.add_column("#", style="dim", justify="right")
table.add_column("Output", overflow="fold")
for r in results:
if r["status"] == "done":
s = r["result"]["output"]
if "class Solution" not in s:
table.add_row(r["id"], Text(repr(s[:300])))
Console().print(table)
Unexpected outputs (12) ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ # ┃ Output ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ find-the-largest-palindrome-divisible-by-k │ '```python\n99999\n](https://leetcode.com/problems/lar │ │ │ gest-palindromic-number/discuss/100000/JavaC%2B%2BPyth │ │ │ on-3-99999)' │ │ maximum-total-area-occupied-by-pistons │ 'duplicate' │ │ find-the-original-typed-string-ii │ 'duplicate =7\n Sponsored by Alibaba Cloud.' │ │ count-connected-components-in-lcm-graph │ 'duplicate' │ │ maximize-amount-after-two-days-of-conversions │ 'To solve this problem, we need to determine the │ │ │ maximum amount of currency we can obtain starting with │ │ │ a given initial currency on both days using the │ │ │ provided conversion rates. The key is to use dynamic │ │ │ programming to keep track of the maximum amount of │ │ │ each currency we can obtain at each step.' │ │ smallest-substring-with-identical-characters-i │ 'inguire' │ │ substring-matching-pattern │ 'inguence\n Sponsored by Alibaba Cloud.' │ │ maximize-subarray-sum-after-removing-all-occurrences-… │ 'inguence\npired.' │ │ shortest-matching-substring │ 'duplicate' │ │ maximize-the-distance-between-points-on-a-square │ 'inguence\n Sponsored by Alibaba Cloud.' │ │ minimum-cost-to-divide-array-into-subarrays │ 'inguire\n Sponsored by Alibaba Cloud.' │ │ maximize-active-section-with-trade-ii │ 'inguire\n Sponsored by Alibaba Cloud.' │ └────────────────────────────────────────────────────────┴────────────────────────────────────────────────────────┘
Another bad answer from the video starts with class Solution, but keeps
adding nested loops until the output is cut off. Show that problem’s saved answer:
example_id = "find-the-lexicographically-largest-string-from-the-box-i"
if example_id in completed:
print(completed[example_id]["result"]["output"])
else:
print(f"No saved answer for {example_id} in this run.")
```python
class Solution:
def answerString(self, word: str, numFriends: int) -> str:
n = len(word)
if n == 0:
return ""
# Initialize the result with the entire word
result = word
# Iterate over all possible splits
for i in range(1, n // numFriends + 1):
# Generate all possible splits of the word into numFriends parts
for j in range(i, n - i + 1, i):
# Generate all possible splits of the word into numFriends parts
for k in range(j, n - j + 1, i):
# Generate all possible splits of the word into numFriends parts
for l in range(k, n - k + 1, i):
# Generate all possible splits of the word into numFriends parts
for m in range(l, n - l + 1, i):
# Generate all possible splits of the word into numFriends parts
for n in range(m, n - m + 1, i):
# Generate all possible splits of the word into numFriends parts
for o in range(n, n - n + 1, i):
# Generate all possible splits of the word into numFriends parts
for p in range(o, n - o + 1, i):
# Generate all possible splits of the word into numFriends parts
for q in range(p, n - p + 1, i):
# Generate all possible splits of the word into numFriends parts
for r in range(q, n - q + 1, i):
# Generate all possible splits of the word into numFriends parts
for s in range(r, n - r + 1, i):
# Generate all possible splits of the word into numFriends parts
for t in range(s, n - s + 1, i):
# Generate all possible splits of the word into numFriends parts
for u in range(t, n - t + 1, i):
# Generate all possible splits of the word into numFriends parts
for v in range(u, n - u + 1, i):
# Generate all possible splits of the word into numFriends parts
for w in range(v, n - v + 1, i):
# Generate all possible splits of the word into numFriends parts
for x in range(w, n - w + 1, i):
# Generate all possible splits of the word into numFriends parts
for y in range(x, n - x + 1, i):
# Generate all possible splits of the word into numFriends parts
for z in range(y, n - y + 1, i):
# Generate all possible splits of the word into numFriends parts
for a in range(z, n - z + 1, i):
# Generate all possible splits of the word into numFriends parts
for b in range(a, n - a + 1, i):
# Generate all possible splits of the word into numFriends parts
for c in range(b, n - b + 1, i):
# Generate all possible splits of the word into numFriends parts
for d in range(c, n - c + 1, i):
# Generate all possible splits of the word into numFriends parts
for e in range(d, n - d + 1, i):
# Generate all possible splits of the word into numFriends parts
for f in range(e, n - e + 1, i):
# Generate all possible splits of the word into numFriends parts
for g in range(f, n - f + 1, i):
# Generate all possible splits of the word into numFriends parts
for h in range(g, n - g + 1, i):
# Generate all possible splits of the word into numFriends parts
for i in range(h, n - h + 1, i):
# Generate all possible splits of the word into numFriends parts
for j in range(i, n - i + 1, i):
# Generate all possible splits of the word into numFriends parts
for k in range(j, n - j + 1, i):
# Generate all possible splits of the word into numFriends parts
for l in range(k, n - k + 1, i):
# Generate all possible splits of the word into numFriends parts
for m in range(l, n - l + 1, i):
# Generate
Close the engine#
%%there --worker
if globals().get("leetcode_engine") is not None:
leetcode_engine.close()
leetcode_engine = None