Wavy String

Generate a wave pattern based on a string

Medium5/15/2024

Problem statement

Given a string, generate a "wave" pattern based on the sequence of characters. Each character in the string will create a peak in the wave, rising and falling around the character. The height of the peak should be equal to the amount of characters in the string. The wave should alternate between peaks and valleys.

For example, given the string hello, the wave pattern would look like this:

    h       e       l        l       o
   h h     e e     l l      l l     o o
  h   h   e   e   l   l    l   l   o   o
 h     h e     e l     l  l     l o     o
h       h       e       l        l       o

For spy, the wave pattern would look like this:

  s   p   y
 s s p p y y
s   s   p   y

Constraints: the input is a single word string with between 3 and 100 characters.

Note: When comparing your output with the expected one, the trailing spaces on each line are ignored.

Problem leaderboard

#
Size
%
Users
#1
145 c.
Top 25%
Natanaelel
#2
148 c.
Top 50%
voytxt
#3
151 c.
Top 75%
maximec-indy
#4
181 c.
Top 100%
Thomasdcrt