The "Count Prefixes of a Given String interview question" is a straightforward string verification task. You are given an array of strings called words and a target string s. Your goal is to determine how many strings in the words array are prefixes of s. A string is a prefix of if starts with .
Companies like Google use the "Count Prefixes of a Given String coding problem" as an introductory warm-up to test basic string manipulation and loop control. It evaluates a candidate's familiarity with string matching functions and their ability to handle basic linear scans over an array. It’s a test of clean coding and efficiency in "String interview pattern" basics.
This problem follows the Linear Scan and String Matching pattern.
words array.startsWith() in Java/JavaScript or s.startswith() in Python) to check if the target string s begins with that word.Words: ["a", "b", "c", "ab", "bc", "abc"],
words array (an empty string is usually considered a prefix of any string).Get comfortable with your programming language's string manipulation library. Knowing the difference between "contains," "prefix," and "suffix" methods is a foundational skill for any "String interview pattern" problem.