Fibonacci String

Published by Deep Xavier in

A Fibonacci string is a precedence of the Fibonacci series. It works with any two characters of the English alphabet (as opposed to the numbers 0 and 1 in the Fibonacci series) as its initial items and concatenates them together as it progresses similarly to that of the Fibonacci series.

Examples

generateString(3, ["j", "h"]) ➞ "j, h, hj"

generateString(5, ["e", "a"]) ➞ "e, a, ae, aea, aeaae"

generateString(6, ["n", "k"]) ➞ "n, k, kn, knk, knkkn, knkknknk"

generateString(1, ["f", "g"]) ➞ "invalid"
// return "invalid" if n is less than 2

Notes

  • Alternatively, you can solve this challenge using a recursive approach if you wish to.
  • A recursive version of this challenge can be found via this link.
Watch a quick demo on how Edabit works.