Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

2.5 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6a26df95efa55a2524399743 Challenge 362: Nonogram Validator 29 challenge-362

--description--

Given an array of clue numbers and an array of cells, determine whether the cells satisfy the nonogram clue.

  • The clue is an array of numbers representing the lengths of consecutive filled cells, in order. For example, a clue of [3, 2] means there should be 3 consecutive filled cells followed by 2 consecutive filled cells, separated by at least one empty cell.
  • The row is an array of 1s (filled) and 0s (empty).

--hints--

is_valid_nonogram([3, 2], [1, 1, 1, 0, 1, 1]) should return True.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_nonogram([3, 2], [1, 1, 1, 0, 1, 1]), True)`)
}})

is_valid_nonogram([3, 2], [0, 1, 1, 1, 1, 1]) should return False.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_nonogram([3, 2], [0, 1, 1, 1, 1, 1]), False)`)
}})

is_valid_nonogram([1, 1, 1, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1]) should return False.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_nonogram([1, 1, 1, 1], [1, 0, 1, 0, 1, 0, 1, 0, 1]), False)`)
}})

is_valid_nonogram([1, 1, 1, 1], [0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0]) should return True.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_nonogram([1, 1, 1, 1], [0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0]), True)`)
}})

is_valid_nonogram([3, 2, 3], [0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0]) should return True.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_nonogram([3, 2, 3], [0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0]), True)`)
}})

is_valid_nonogram([3, 2, 3], [0, 0, 0, 1, 0, 0, 1, 0, 0, 0]) should return False.

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertIs(is_valid_nonogram([3, 2, 3], [0, 0, 0, 1, 0, 0, 1, 0, 0, 0]), False)`)
}})

--seed--

--seed-contents--

def is_valid_nonogram(clue, cells):

    return clue

--solutions--

def is_valid_nonogram(clue, cells):
    runs = []
    count = 0

    for i in range(len(cells) + 1):
        if i < len(cells) and cells[i] == 1:
            count += 1
        elif count > 0:
            runs.append(count)
            count = 0

    if len(runs) != len(clue):
        return False
    return all(runs[i] == clue[i] for i in range(len(runs)))