Problem 249227 · medium · Phase 02 Linear Data Structures

Word Search Tally

2d-lists · strings · sliding-window

Given a grid of single-character strings grid and a string word of length at least 2, count how many times word appears reading left to right within a row or top to bottom within a column. Overlapping occurrences count separately.

Examples

Input:  grid = [["c", "a", "t"],
                ["a", "x", "o"],
                ["t", "o", "p"]], word = "cat"
Output: 2
Explanation: "cat" is the first row and also the first column.

Input:  grid = [["c", "a", "t"],
                ["a", "x", "o"],
                ["t", "o", "p"]], word = "aa"
Output: 0

Input:  grid = [["a", "a", "a"]], word = "aa"
Output: 2

Constraints

  • 1 <= rows, cols <= 100, 2 <= len(word) <= 20

Goals

  • Scan rows and columns for a fixed pattern
  • Allow overlapping matches and avoid double counting
Starting Python…