Skip to main content
Back to problems
#1023
Medium Algorithms

Camelcase matching

Array Two Pointers String Trie String Matching
65.1% acceptance
Feb 25, 2026
979
348
Given an array of strings queries and a string pattern, return a boolean array answer where answer[i] is true if queries[i] matches pattern, and false otherwise. A query word queries[i] matches pattern if you can insert lowercase English letters into the pattern so that it equals the query. You may insert a character at any position in pattern or you may choose not to insert any characters at all.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn camel_match(queries: Vec<String>, pattern: String) -> Vec<bool> {
    let p: Vec<char> = pattern.chars().collect();
    queries.iter().map(|q| {
      let mut pi = 0;
      for c in q.chars() {
        if pi < p.len() && c == p[pi] { pi += 1; }
        else if c.is_uppercase() { return false; }
      }
      pi == p.len()
    }).collect()
  }
}