Find Every Campaign Hashtag Hidden in a Letter Grid

Last updated: November 29, 2026

Quick Overview

For a TikTok branded word-search effect, you get a grid of letters and a list of campaign hashtags. Return every hashtag that can be spelled by moving between horizontally or vertically adjacent cells without reusing a cell within one word.

TikTok
Coding & Algorithms
Software Engineer
TikTok
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


For a TikTok branded word-search effect, you get a grid of letters and a list of campaign hashtags. Return every hashtag that can be spelled by moving between horizontally or vertically adjacent cells without reusing a cell within one word.

This combines a trie with grid backtracking and is a well-known TikTok onsite style problem when interviewers want to see pruning beyond a naive per-word search. They check that you search all words in one DFS pass, avoid duplicate results, and prune trie branches once their words are found.

What the Interviewer Expects
  • Explains why searching each word separately is too slow for large word lists
  • Builds a trie and drives one DFS per starting cell from it
  • Marks visited cells in place and restores them
  • Removes found words and empty trie nodes to prune later searches
  • Gives a defensible complexity bound
Key Topics to Cover
tries
backtracking
grid DFS
pruning
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you allow diagonal moves, and how does the bound change?
  • What if the grid is 1000 by 1000 but words are at most 6 letters?
  • How would you return the cell path for each word so the effect can highlight it?
  • How would you parallelize across starting cells?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Grid of single lowercase letters, up to about 12 by 12. Up to tens of thousands of words, each up to 10 letters. Return each found word once, sorted. Adjacency is 4-directional, and a cell cannot repe...

High-Level Design

Insert all words into a trie whose terminal nodes store the full word. Start a DFS from every cell whose letter is a child of the root. The DFS carries the current trie node, so we only step into neig...


Submit Your Answer
Markdown supported