Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This comment is hidden because it contains spoiler information about the solution
This is a clever solution!
This is 100% correct, parts of the description are not highlighted enough, like a nuance of this would be it needs to be the FIRST result, although it is stated, it melds into the rest of the description and does not stand out.
I understood this description immediately!! Also the original should have more examples (i.e. longest string in array not necessarily being in the answer)
This is great, thank you, Psychemaster!
This changes the array as well.
Depends on the size of the array.
Thank you. Went to the comments section just to check if it's the description or my poor English.
This should have been the actual description.
Gotta say, I like how the test cases in this one heavily discouraged an iterative solution - pretty neat!
Slightly Clearer Description
Task
You are given an array of string inputs
strarr
and an integerk
.Your task is to return the longest possible string that can be derived by combining
k
consecutive elements of the inputstrarr
.Example
longest_consec(["red", "orange", "yellow", "green", "blue", "indigo", "violet"], 2)
should return"orangeyellow"
Notes
In the case of there being multiple possible matches, only the first one will be considered correct.
In any of the following cases, the return value should be an empty string
""
:strarr.length === 0
strarr.length < k
k <= 0
Also, even if you had to go through the array twice that's 2n wheras nlogn still takes longer for large n. And in any case 2n is O(n).
I liked it, looks cool for small arrays
uhhhhhhhhh no you can keep track of the 2 greatest numbers visited so far in the array as you loop through lol
You have to go through the whole list and then go back and set the numbers, this isn't efficient.
Loading more items...