Find max word letter span
Problem Description
Implement a function that takes an input text string and computes the maximum "word letter span" found within it. The function should return both:
- The maximum span value.
- A list of all words from the input text that achieve this maximum span.
Definition of Word Letter Span
A word's letter span is defined as the absolute distance between its first and last alphabetic letters.
- Letter positions are assigned from
a=0toz=25. - Capitalization is ignored (e.g., 'A' is treated as 'a').
- Punctuation and non-letter characters within a word should be ignored when determining the first and last alphabetic letters.
- Words that begin and end with the same letter have a span of 0.
- The order of the boundary letters inside the word does not affect the span calculation (e.g., 'az' and 'za' both yield a span of 25).
Examples
- "cab" -> 1 (c=2, b=1; |2-1|=1)
- "pat" -> 4 (p=15, t=19; |15-19|=4)
- "Float" -> 14 (F/f=5, t=19; |5-19|=14)
- "wood" -> 19 (w=22, d=3; |22-3|=19)
- "would" -> 19 (w=22, d=3; |22-3|=19)
- "I" -> 0 (I/i=8, i=8; |8-8|=0)
- "pop" -> 0 (p=15, p=15; |15-15|=0)
- "can't" -> 17 (c=2, t=19; |2-19|=17)
- "cannot." -> 17 (c=2, t=19; |2-19|=17)
Deliverables and Considerations
- Return Format: Clearly state whether the returned list of words contains their original surface forms or normalized forms (e.g., lowercase, stripped of punctuation).
- Complexity Analysis: Analyze the time and space complexity of your solution.
- Edge Cases: Explain how your solution handles:
- Ties (multiple words achieving the same maximum span).
- Duplicate words in the input text.
- Contractions and hyphenated words (e.g., "can't", "rock-solid").
- Texts containing no alphabetic words.
AI interview prep
Core dilemma
Accurately and efficiently extracting 'words' and their boundary letters from a potentially complex text string, while robustly handling various edge cases (punctuation, capitalization, contractions, empty text) and optimizing for performance on large inputs.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Find max word letter span
Problem Description
Implement a function that takes an input text string and computes the maximum "word letter span" found within it. The function should return both:
- The maximum span value.
- A list of all words from the input text that achieve this maximum span.
Definition of Word Letter Span
A word's letter span is defined as the absolute distance between its first and last alphabetic letters.
- Letter positions are assigned from
a=0toz=25. - Capitalization is ignored (e.g., 'A' is treated as 'a').
- Punctuation and non-letter characters within a word should be ignored when determining the first and last alphabetic letters.
- Words that begin and end with the same letter have a span of 0.
- The order of the boundary letters inside the word does not affect the span calculation (e.g., 'az' and 'za' both yield a span of 25).
Examples
- "cab" -> 1 (c=2, b=1; |2-1|=1)
- "pat" -> 4 (p=15, t=19; |15-19|=4)
- "Float" -> 14 (F/f=5, t=19; |5-19|=14)
- "wood" -> 19 (w=22, d=3; |22-3|=19)
- "would" -> 19 (w=22, d=3; |22-3|=19)
- "I" -> 0 (I/i=8, i=8; |8-8|=0)
- "pop" -> 0 (p=15, p=15; |15-15|=0)
- "can't" -> 17 (c=2, t=19; |2-19|=17)
- "cannot." -> 17 (c=2, t=19; |2-19|=17)
Deliverables and Considerations
- Return Format: Clearly state whether the returned list of words contains their original surface forms or normalized forms (e.g., lowercase, stripped of punctuation).
- Complexity Analysis: Analyze the time and space complexity of your solution.
- Edge Cases: Explain how your solution handles:
- Ties (multiple words achieving the same maximum span).
- Duplicate words in the input text.
- Contractions and hyphenated words (e.g., "can't", "rock-solid").
- Texts containing no alphabetic words.