Is a String Stretched?

Published by Helen Yu in

Write a function that returns true if the first string is the second string stretched, and false otherwise. A stretch is to repeat each character in a string the same number of times.

Examples

is_stretched("pppaaannndddaaa", "panda") ➞ true

is_stretched("sssshhiipp", "ship") ➞ false

is_stretched("magnet", "magnet") ➞ true

is_stretched("magneto", "magnet") ➞ false

Notes

  • Both strings must contain the same letters in order for the stretch to be valid.
  • All strings will be in lower case letters.
Watch a quick demo on how Edabit works.