Maximum-Value Word Derivation Path
Updated
Problem statement
In one derivation step, rearrange all the letters of a word and add exactly one letter. Existing letters cannot be removed or replaced, and repeated letters count separately.
Each vocabulary[i] has integer value values[i]. Given start and target, return a derivation path from start to target whose total word value is largest.
For this exercise, assume vocabulary labels are unique, both endpoints are listed, and every intermediate word must also be listed. The total includes every word in the path, including start and target.
For this exercise, assume equal totals choose the lexicographically smallest complete word list: compare the first differing word using ordinary lowercase lexicographic order. Return an empty array if target is unreachable. When start equals target, return the one-word zero-step path.
Function
bestDerivationPath(start: String, target: String, vocabulary: String[], values: int[]) → String[]Examples
Example 1
start = "a"target = "abc"vocabulary = ["a","ab","ac","abc"]values = [1,3,8,2]return = ["a","ac","abc"]This example chooses a, ac, abc with total 11 instead of the total 6 through ab.
Example 2
start = "ab"target = "abcd"vocabulary = ["ab","abc","acb","abcd"]values = [2,5,5,3]return = ["ab","abc","abcd"]This tie selects ab, abc, abcd before ab, acb, abcd in lexicographic path order.
Example 3
start = "two"target = "woutx"vocabulary = ["two","woutx"]values = [4,9]return = []There is no listed length-four intermediate word, so no path exists.
Constraints
- For this exercise, assume
1 <= vocabulary.length <= 25andvalues.length == vocabulary.length. - Every vocabulary word is a unique nonempty lowercase English string of length at most 12. Start and target occur in vocabulary.
- For this exercise, assume
-1000 <= values[i] <= 1000.
More Duolingo Phone Screen questions
- Rank Word-Translation Hints from Sentence TranslationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Group Timestamps into Consecutive-Day IntervalsPHONE SCREEN · Seen Nov 2026
- Return Every Matching DecryptionPHONE SCREEN · Seen Nov 2026
- Visit Desired Attractions Without Reusing a TrailPHONE SCREEN · Seen Oct 2026
- Correct an In-Place Array ReversalPHONE SCREEN · Seen Oct 2026
- Count Starts Reaching a Grid MaximumPHONE SCREEN · Seen Oct 2026
- Select the Top User MatchesPHONE SCREEN · Seen Oct 2026
- Sum All Values in a Binary TreePHONE SCREEN · Seen Oct 2026
- User Resource Transition ProbabilitiesPHONE SCREEN · Seen Oct 2026
- Encrypt and Decrypt StringsPHONE SCREEN · Seen Apr 2026
Similar questions at other companies
- Shortest Word Chain Between Two WordsFanatics · PHONE SCREEN
- Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
- All Halfway Courses Across Course TracksCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Minimum Total Layover WaitGoogle · PHONE SCREENGoogle interview questions
- Longest Palindromic SubstringSiemens · PHONE SCREEN
- Query Words Within K PositionsPalantir · PHONE SCREENPalantir interview questions
- Resolve Variable Equations with Dependency ErrorsApplied Intuition · PHONE SCREENApplied Intuition interview questions
- Edit DistanceDP World · PHONE SCREEN
- Nested Substitutions with Cycle DetectionKikoff · PHONE SCREENKikoff interview questions
- Shortest Paths in a Nonnegative Directed GraphNation with NaMo · PHONE SCREEN