04_longest_consecutive/script.rb
# consecutive strings : follow one after another without an interruption
consecutive strings : follow one after another without an interruption
consecutive strings : follow one after another without an interruption
def longest_consec(strarr, _k)
  biggest = ''
  return biggest if _k < 1 || _k > strarr.length
  strarr.each_index do |i|
    string = strarr[i]
    if _k > 1
      (1..(_k - 1)).each do |j|
        string += strarr[i + j] if i + j < strarr.length
      end
    end
    biggest = string.length > biggest.length ? string : biggest
  end
  biggest
end
def longest_consec ( strarr , _k ) biggest = '' return biggest if _k < 1 || _k > strarr . length strarr . each_index do | i | string = strarr [ i ] if _k > 1 ( 1 .. ( _k - 1 ) ) . each do | j | string += strarr [ i + j ] if i + j < strarr . length end end biggest = string . length > biggest . length ? string : biggest end biggest end
consecutive strings : follow one after another without an interruption
consecutive strings : follow one after another without an interruption
strarr
<not_specific>
_k
<not_specific>