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:

CreatedMar 15, 2018
PublishedMar 31, 2018
Warriors Trained1356
Total Skips40
Total Code Submissions4276
Total Times Completed530
JavaScript Completions220
Ruby Completions47
Python Completions281
Total Stars70
% of votes with a positive feedback rating92% of 151
Total "Very Satisfied" Votes131
Total "Somewhat Satisfied" Votes16
Total "Not Satisfied" Votes4
Total Rank Assessments7
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • Firefly2002 Avatar
  • myjinxin2015 Avatar
  • FArekkusu Avatar
Ad