5 kyu
Find the Word Pair!
220 of 530Firefly2002
Description:
Given an array of words and a target compound word, your objective is to find the two words which combine into the target word, returning both words in the order they appear in the array, and their respective indices in the order they combine to form the target word. Words in the array you are given may repeat, but there will only be one unique pair that makes the target compound word. If there is no match found, return null
/nil
/None
.
Note: Some arrays will be very long and may include duplicates, so keep an eye on efficiency.
Examples:
fn(['super','bow','bowl','tar','get','book','let'], "superbowl") => ['super','bowl', [0,2]]
fn(['bow','crystal','organic','ally','rain','line'], "crystalline") => ['crystal','line', [1,5]]
fn(['bow','crystal','organic','ally','rain','line'], "rainbow") => ['bow','rain', [4,0]]
fn(['bow','crystal','organic','ally','rain','line'], "organically") => ['organic','ally', [2,3]]
fn(['top','main','tree','ally','fin','line'], "mainline") => ['main','line', [1,5]]
fn(['top','main','tree','ally','fin','line'], "treetop") => ['top','tree', [2,0]]
Have fun, and if you enjoyed it don't forget to rank & upvote! :)
Arrays
Performance
Algorithms
Similar Kata:
Stats:
Created | Mar 15, 2018 |
Published | Mar 31, 2018 |
Warriors Trained | 1356 |
Total Skips | 40 |
Total Code Submissions | 4276 |
Total Times Completed | 530 |
JavaScript Completions | 220 |
Ruby Completions | 47 |
Python Completions | 281 |
Total Stars | 70 |
% of votes with a positive feedback rating | 92% of 151 |
Total "Very Satisfied" Votes | 131 |
Total "Somewhat Satisfied" Votes | 16 |
Total "Not Satisfied" Votes | 4 |
Total Rank Assessments | 7 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |