Closest Rhyming Word
Updated
Problem statement
Given a target word target and an array of candidate words words, return the candidate with the largest rhyme score.
The rhyme score is the number of matching characters in the longest common suffix of target and a candidate. If several candidates have the same score, return the one that appears first in words.
Function
closestRhymingWord(target: String, words: String[]) → StringExamples
Example 1
target = "thunder"words = ["plunder","wonder","rain"]return = "plunder"plunder and thunder share the suffix under, which is longer than every other shared suffix.
Example 2
target = "stone"words = ["alone","phone","stove"]return = "alone"alone and phone tie with the suffix one, so the earlier candidate is returned.
Example 3
target = "cat"words = ["dog","sun","map"]return = "dog"No candidate shares a non-empty suffix with target, so every score is 0 and the first candidate wins.
Constraints
1 <= target.length <= 10^5.1 <= words.length <= 10^5.- Every word contains only lowercase English letters.
- The total number of characters across
wordsis at most10^5.
More Accenture interview questions
- Nearest Composite NumberOA · Seen Sep 2026
- Minimum Password IncrementsOA · Seen Sep 2026
- Reduce a Number to One DigitOA · Seen Sep 2026
- Candy DistributionOA · Seen Sep 2026
- Customers Who Never OrderedOA · Seen Sep 2026
- Economical TripOA · Seen Sep 2026
- Coin ChangeOA · Seen Sep 2026
- Validate Email AddressOA · Seen Sep 2026
- Array Leader ElementsOA · Seen Nov 2025
- Alternating Index Square SumONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- REST API: Country CodesHackerRank · OAHackerRank interview questions
- Fill One Exact-Length Binary WindowAmazon · OA
- Remove Vowels from a StringHSBC · OAHSBC interview questions
- Branch with the Most FilesCapital One · OACapital One interview questions
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- Maximum Ones After K OperationsGoldman Sachs · OAGoldman Sachs interview questions
- Total Each Letter's Count in an Encoded StringIBM · OAIBM interview questions
- Robot Stops Left or Right (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
- Find Words That Can Be Formed by CharactersTabaPay · OA
- Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions