Created
September 23, 2019 15:47
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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