Skip to content

Instantly share code, notes, and snippets.

@venelrene
Created September 23, 2019 15:47
Show Gist options
  • Select an option

  • Save venelrene/c3ffc717703f36ae8e8b6355ea676994 to your computer and use it in GitHub Desktop.

Select an option

Save venelrene/c3ffc717703f36ae8e8b6355ea676994 to your computer and use it in GitHub Desktop.
You are given an array 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.
defmodule Longestconsec do
def longest_consec(strarr, k)
when length(strarr) == 0
when k > length(strarr)
when k <= 0,
do: ""
def longest_consec(strarr, k) do
Enum.chunk_every(strarr, k, 1)
|> Enum.map(&Enum.join/1)
|> Enum.max_by(&String.length/1)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment