Count Prefix-Related Word Pairs
Updated
Problem statement
You are given an array of strings words. Count unordered index pairs (i, j) with i < j for which either word is a prefix of the other.
Equal words qualify.
Function
countPrefixPairs(words: String[]) → longExamples
Example 1
words = ["a","ab","abc","b"]return = 3The qualifying pairs are (a, ab), (a, abc), and (ab, abc).
Example 2
words = ["x","x","xy"]return = 3The two equal words qualify, and each is a prefix of xy.
Constraints
0 <= words.length <= 20000 <= words[i].length <= 1000- Words contain lowercase English letters.
More ZipRecruiter Online Assessment questions
- Four-Level Banking System with Scheduled PaymentsOA · Seen Oct 2026
- Count Three-Digit Numbers with Distinct DigitsOA · Seen Oct 2024
- Longest Frequency-Bounded SubarrayOA · Seen Oct 2024
- Minimum Changes to Draw a YOA · Seen Oct 2024
- Apply Binary State OperationsOA · Seen Sep 2024
- Simulate Orchard Rot SpreadOA · Seen Sep 2024
- Compare Odd- and Even-Index SumsOA · Seen Sep 2024
- Coordinate Removals with Column GravityOA · Seen Sep 2024
- Lexicographically Smallest End ReversalOA · Seen Sep 2024
- Recursively Expanded Shell Command CountsOA · Seen Sep 2024
Similar questions at other companies
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- Find Words That Can Be Formed by CharactersTabaPay · OA
- Word Frequency Counts in Alphabetical OrderAbridge · OAAbridge interview questions
- Count Multiples of Three with Two SevensHudson River Trading · OAHudson River Trading interview questions
- Customer Signer ScreeningState Farm · OA
- REST API: Highest International StudentsRippling · OARippling interview questions
- String-Pair Frequency SimilarityIBM · OAIBM interview questions
- Find Sliding-Window Pattern Start IndicesVisa · OAVisa interview questions
- Closest ColorTwo Sigma · OATwo Sigma interview questions
- Number-Character Bijective MappingAdobe · OAAdobe interview questions