Fair Rations
easy⏱ 15 mintypescriptchallengesproblem-solving-basic-
Runs in your browser
- Before starting
- Use a supported browser; initial dependencies may need internet.
- What it proves
- Run shows output; Test checks the authored cases, not every possible input.
- When finished
- Stop active runs when finished. No cloud infrastructure is provisioned by this exercise.
LEARN BY DOINGPut your intuition to work3 steps
Fair Rations
Use the lesson’s examples and explanation to check your idea.
Personal reflection. Nothing is sent to an AI service.Before you start
Browser lesson checks; review each requirement in Tests.
Catalog level: Easy · Estimated time: 15 min. Your prior experience can change the difficulty.
Sample case — your program reads stdin and prints to stdout.
Need a hand?
Start with a small test case. Hints progress from an idea to an explanation and, when requested, code.
Starter N people with B[i] loaves. Each operation gives 1 loaf to person i and 1 to neighbor (i-1 or i+1). Find minimum loaves to make all counts even, or return 'NO'.
Example (0-indexed): B=[2,3,4,5,6] → person 1 has 3 (odd) → give to persons 1 and 2: [2,4,5,5,6] → person 2 has 5 (odd) → give to persons 2 and 3: [2,4,6,6,6] → all even. Total: 4 loaves distributed.
Input format
First line: N. Second line: N space-separated integers (initial loaves).
Output format
The minimum number of loaves (as string) or 'NO'.
Constraints
2 ≤ N ≤ 1000, 1 ≤ B[i] ≤ 10