Ask precisely
Read · 1 of 2
What a good request contains
The task in one sentence. The input and output format. The limits: "n up to 100,000" tells the AI a loop inside a loop won't do. Examples, including an edge case. And: "also give me tests".
Everything you leave out, the AI guesses. Edge cases are exactly where it guesses wrong.
Read this lesson as text
A clear request is half the work of getting correct code.
What a good request contains
The task in one sentence. The input and output format. The limits: "n up to 100,000" tells the AI a loop inside a loop won't do. Examples, including an edge case. And: "also give me tests".
Everything you leave out, the AI guesses. Edge cases are exactly where it guesses wrong.
Pick the request
# You need: the length of the longest run of equal numbers next to each other.
Which request will most likely get correct, fast code the first time?
- Write code for longest run.
- Write a Python function that returns the length of the longest run of equal neighbouring numbers in a list. The list has 0 to 100,000 numbers; return 0 for an empty list. Example: [1, 1, 2, 2, 2, 1] → 3. Include tests for empty, single and all-equal lists.
- You are an expert programmer. Write the best, most optimised code for finding runs in arrays.
Show the answer
Write a Python function that returns the length of the longest run of equal neighbouring numbers in a list. The list has 0 to 100,000 numbers; return 0 for an empty list. Example: [1, 1, 2, 2, 2, 1] → 3. Include tests for empty, single and all-equal lists.. It pins down the exact task, the limits, what to do with an empty list, an example, and asks for tests. "Expert" and "best" add nothing the AI can act on.