Company: NxtWave
Difficulty: medium
Pleasant melody Problem Description You are composing a melody using only two notes: a and b . A melody is considered Pleasant if it does not contain more than two identical notes consecutively. Given a string representing a melody, find the longest Pleasant substring of the melody. Note: If there are multiple substrings of the same maximum length, return the first one that appears in the string. Examples Example 1: Input: melody = "aaabbb" Output: "aabb" Explanation: Both "aaa" and "bbb" are invalid (too many consecutive notes). The longest Pleasant substring possible is "aabb". Example 2: Input: melody = "ababab" Output: "ababab" Explanation: This entire melody is harmonious since no note repeats more than twice consecutively.