Given a word and a crossword grid represented by a single row/column line, determine where the word can be placed by matching characters and blanks.
Problem Summary
You are given a crossword-like line of cells and a word to place. Some cells already contain letters, while others may be blank or blocked. Your task is to determine whether the word can be placed so that it fits the available cells and matches any pre-filled letters.
A placement is valid if:
- the word has the same length as the available segment,
- every non-empty cell already on the board matches the corresponding letter of the word,
- and the word does not conflict with blocked cells or boundaries.
This is a straightforward string/array matching task where you scan candidate positions and check whether the word can be aligned without contradiction.
Input Format
- The input describes a crossword segment and a target word.
- The exact representation of the cells is platform-specific, but the core task is to check whether the word can be placed consistently across a candidate segment.
- Treat filled letters as fixed characters and blanks as flexible cells.
Output Format
- Print or return whether the word can be placed successfully.
- If the platform asks for a location, output the valid starting position; otherwise output a boolean-style answer such as YES/NO.
Constraints
- Word length is small enough for linear or near-linear scanning.
- Character comparison is case-sensitive unless stated otherwise.
- Use only the information in the provided grid/segment; do not assume missing cells.
Example 1
Input
segment = "?a?c?", word = "abc"
Output
YES
Explanation
The word can fit if the first, third, and fifth cells are blanks and the middle fixed letters match the word where they overlap.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.