Skip to the code
cf.
+10 XP

#716 Does the Query Fit?

easy

A file finder shows UserProfileCard.tsx when you type upc, because the letters u, p, c appear in that order in the name, with gaps allowed.

Write fits(query, name) that returns true if every character of query appears in name in the same order, ignoring upper and lower case, and false otherwise. An empty query fits every name.

Example 1

Input: query = "upc", name = "UserProfileCard.tsx"
Output: true

U, then P, then C, in order.

Example 2

Input: query = "cpu", name = "UserProfileCard.tsx"
Output: false

There is a c and a p, but no u after them in that order.

Constraints

  • 0 <= query.length <= 100
  • 0 <= name.length <= 10^4
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).