Longest Word Containing Another Input
Updated
Problem statement
Given an array of nonempty lowercase English strings words, find an input string that contains at least one other input string as a contiguous substring.
An input at index i qualifies when some index j != i satisfies that words[j] occurs in words[i]. Equal strings at different indices count as a match; a string does not match itself at the same index.
Return the longest qualifying string. If several qualifying strings have the same length, return the one appearing first in the input array. Return the empty string "" when none qualifies. Matching is literal and case-sensitive.
Optimization discussion
A direct baseline checks every ordered pair and compares characters at every possible substring start. Explain its time and space cost, then describe two faster approaches and implement one. Length-based pruning and multi-pattern search are useful directions.
Only the returned string is graded; the complexity discussion is interview practice.
Function
findContainingWord(words: String[]) → StringExamples
Example 1
words = ["programming","am","pro"]return = "programming"programming contains both am and pro. It is the longest qualifying input.
Example 2
words = ["category","cat"]return = "category"cat is a prefix substring of category. The containing word is returned.
Example 3
words = ["dog","cat","bird"]return = ""No input contains another listed input, so return the empty string.
Constraints
1 <= words.length <= 200.1 <= words[i].length <= 2000.- The total length of all input strings is at most
20000. - Every string contains only letters
athroughz; duplicate strings are allowed.
More Meta Phone Screen questions
- Convert a Sorted Linked List to a Balanced BSTPHONE SCREEN · Seen Nov 2026
- Fuzzy Word Lookup With One Misspelled LetterPHONE SCREEN · Seen Nov 2026
- Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Run-Length Encoded Vector Dot ProductPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Time to Buy and Sell StockPHONE SCREEN · Seen Nov 2026
- First Element Greater Than KPHONE SCREEN · Seen Nov 2026
- Count Events in Rolling Minute WindowsPHONE SCREEN · Seen Oct 2026
- Valid Word AbbreviationPHONE SCREEN · Seen Oct 2026
- Shortest Path in a Binary MatrixPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Word Break IIAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Word Break IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Word Search IIKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Keyboard Autocomplete SuggestionsLyft · ONSITE INTERVIEWLyft interview questions
- Longest Common Parent DirectoryGoogle · ONSITE INTERVIEWGoogle interview questions
- Find All Word Occurrences in TextSentry · PHONE SCREENSentry interview questions
- Find the Words for Each PrefixDocuSign · PHONE SCREENDocuSign interview questions
- Highlight and Rank Overlapping CitationsHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
- Design Search Autocomplete SystemRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
- Deterministic Word Guess SolverAtlassian · ONSITE INTERVIEWAtlassian interview questions
Meta interview experiences
- Meta PhD SWE Intern AI Coding Phone Screen: 1 Experience
- Meta Business Support Engineer Phone Screen: 1 Experience
- Meta Software Engineer Onsite Questions: 3 Experiences
- Meta AI Native Engineer OA and Onsite: 1 Experience
- Meta AI-Native Coding Interview: 3 Experiences
- Meta Production Engineer Intern Questions: 6 Experiences