10.22 Insert Stars
10.22.1 Problem Metadata
- Platform: Firecode.io
- Problem ID: Insert Stars
- Difficulty: Level 2
- URL: https://www.firecode.io/
- Tags:
- Techniques: Recursion, String
10.22.2 Description
Given a string s, recursively build a new string where any pair of identical adjacent characters is separated by a '*'.
10.22.5 Solution - Recursive Pair Expansion
10.22.5.1 Walkthrough
Base case is a single character. For longer strings, compare the first two characters. If equal, return first + "*" + recurse(s[1:]); otherwise, return first + recurse(s[1:]).