6 kyu

Consecutive strings

2,508 of 82,809g964

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 Trained240979
Total Skips55841
Total Code Submissions521913
Total Times Completed82809
Ruby Completions2508
Python Completions27572
JavaScript Completions24644
CoffeeScript Completions32
Haskell Completions725
Clojure Completions221
C# Completions4774
Java Completions8746
Elixir Completions321
C++ Completions3464
PHP Completions2000
TypeScript Completions1897
Crystal Completions31
F# Completions99
C Completions1078
OCaml Completions52
Rust Completions1231
Swift Completions644
Go Completions1918
R Completions167
Shell Completions90
Kotlin Completions826
PowerShell Completions78
Julia Completions81
Scala Completions298
Nim Completions18
Reason Completions4
Racket Completions41
Dart Completions541
Haxe Completions14
Pascal Completions12
Raku Completions8
Lua Completions129
Perl Completions24
Elm Completions9
COBOL Completions8
D Completions8
Erlang Completions11
Prolog Completions9
Total Stars3551
% of votes with a positive feedback rating85% of 8304
Total "Very Satisfied" Votes6264
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