A small library + console sample to search a character matrix for the Top 10 most repeated words coming from a word stream.
Matches are scanned horizontally (left→right) and vertically (top→bottom).
- 🔍 Finds words spanning rows and columns.
- 🔟 Returns the Top 10 words by frequency in the input stream that also exist in the matrix (ties resolved alphabetically).
🅰️ Case-sensitive matching (inputs must match exactly).- 🧪 Unit tests with xUnit.
WordFinder.sln
├─ WordFinderLib/ # WordFinder class (library)
│ └─ WordFinder.cs
├─ WordFinderApp/ # Optional console app (manual run)
│ └─ Program.cs
└─ WordFinder.Tests/ # xUnit tests
└─ WordFinderTests.cs
1) Build & Test (CLI)
dotnet build
dotnet test
2) Run the console sample
dotnet run --project WordFinderApp
Matrix
a b c d c
f g w i o
c h i l l
p q n s d
u v d x y
Word stream
["cold", "wind", "snow", "chill"]
Result
["chill", "cold", "wind"]
- Precomputes a set with all substrings from every row and every column.
- For every word in the input stream, increments its count if it exists in that set.
- Finally sorts by count desc, then word asc, and takes Top 10.
Complexity (sketch): building the set is roughly O(R*C*(R+C))
substrings with hashing; lookups are O(1)
average per stream item.
- Case-sensitive search (e.g.,
Chill
≠chill
). - Duplicates in the stream increase the count (e.g., if
"wind"
appears twice, it counts twice). - Returns an empty list if there are no matches.
This project is licensed under the MIT License. See LICENSE
for details.