Check That a Gesture Sequence Matches a Shortcut Pattern

Last updated: November 29, 2026

Quick Overview

Given a pattern string such as 'abba' and a space-separated sequence of gestures such as 'swipe tap tap swipe', return True if there is a one-to-one mapping between pattern letters and gestures that turns the pattern into the sequence.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given a pattern string such as 'abba' and a space-separated sequence of gestures such as 'swipe tap tap swipe', return True if there is a one-to-one mapping between pattern letters and gestures that turns the pattern into the sequence.

Framed around configurable gesture shortcuts on Android or Pixel devices. The interviewer is checking that you enforce a bijection (two maps or a map plus a used set), since a single dictionary passes many cases but fails when two letters map to the same gesture.

What the Interviewer Expects
  • Notices the mapping must be one-to-one in both directions
  • Uses two dictionaries or a map plus a reverse set
  • Rejects length mismatches early
  • Gives a counterexample where one map alone fails
  • Writes concise, correct code
Key Topics to Cover
Hash Map
Bijection
Strings
Pattern Matching
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
  • What if gestures are not separated and you must find any valid split (word pattern II)?
  • How would you check that many sequences match the same pattern efficiently?
  • Canonicalize both sides into first-occurrence index lists; why does that also work?
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
  • Input: pattern of lowercase letters, sequence of gesture tokens separated by single spaces.
  • Output: True if each letter maps to exactly one gesture and each gesture to exactly one letter.
  • Th...
High-Level Design

Split the sequence into tokens. Walk letters and tokens together, keeping l2g (letter to gesture) and g2l (gesture to letter). For each pair, if either side already has a mapping that disagrees, r...


Submit Your Answer
Markdown supported