6 kyu

Consecutive strings

24,593 of 82,622g964

Description:

You are given an array(list) strarr of strings and an integer k. Your task is to return the first longest string consisting of k consecutive strings taken in the array.

Examples:

strarr = ["tree", "foling", "trashy", "blue", "abcdef", "uvwxyz"], k = 2

Concatenate the consecutive strings of strarr by 2, we get:

treefoling   (length 10)  concatenation of strarr[0] and strarr[1]
folingtrashy ("      12)  concatenation of strarr[1] and strarr[2]
trashyblue   ("      10)  concatenation of strarr[2] and strarr[3]
blueabcdef   ("      10)  concatenation of strarr[3] and strarr[4]
abcdefuvwxyz ("      12)  concatenation of strarr[4] and strarr[5]

Two strings are the longest: "folingtrashy" and "abcdefuvwxyz".
The first that came is "folingtrashy" so 
longest_consec(strarr, 2) should return "folingtrashy".

In the same way:
longest_consec(["zone", "abigail", "theta", "form", "libe", "zas", "theta", "abigail"], 2) --> "abigailtheta"

n being the length of the string array, if n = 0 or k > n or k <= 0 return "" (return Nothing in Elm, "nothing" in Erlang).

Note

consecutive strings : follow one after another without an interruption

Fundamentals

More By Author:

Check out these other kata created by g964

Stats:

CreatedJan 25, 2016
PublishedJan 25, 2016
Warriors Trained240603
Total Skips55785
Total Code Submissions521163
Total Times Completed82622
Ruby Completions2508
Python Completions27500
JavaScript Completions24593
CoffeeScript Completions32
Haskell Completions722
Clojure Completions221
C# Completions4768
Java Completions8737
Elixir Completions321
C++ Completions3450
PHP Completions1999
TypeScript Completions1893
Crystal Completions31
F# Completions99
C Completions1077
OCaml Completions51
Rust Completions1225
Swift Completions644
Go Completions1907
R Completions166
Shell Completions90
Kotlin Completions823
PowerShell Completions78
Julia Completions81
Scala Completions297
Nim Completions18
Reason Completions4
Racket Completions41
Dart Completions535
Haxe Completions14
Pascal Completions12
Raku Completions7
Lua Completions129
Perl Completions24
Elm Completions9
COBOL Completions8
D Completions8
Erlang Completions11
Prolog Completions9
Total Stars3545
% of votes with a positive feedback rating85% of 8301
Total "Very Satisfied" Votes6261
Total "Somewhat Satisfied" Votes1653
Total "Not Satisfied" Votes387
Ad
Contributors
  • g964 Avatar
  • myjinxin2015 Avatar
  • cacr Avatar
  • Chrono79 Avatar
  • kazk Avatar
  • Blind4Basics Avatar
  • monadius Avatar
  • hobovsky Avatar
  • solitude Avatar
  • trashy_incel Avatar
  • looplopp Avatar
  • user8436785 Avatar
  • akar-0 Avatar
  • Glinator Avatar
  • Just4FunCoder Avatar
  • KayleighWasTaken Avatar
  • saudiGuy Avatar
Ad