6 kyu

Chunky strings

Description:

This kata concerns a string composed of 'chunks'.

A chunk is either:

  • A single alphabetic character

or:

  • Two chunks enclosed in square brackets [ and ]

A 'chunky string' is a string consisting of exactly one chunk. Here are some examples of chunky strings:

'x'
'[xy]'
'[x[yy]]'
'[[xy]y]'
'[[ab][ab]]'
'[c[o[d[e[w[a[rs]]]]]]]'

For this task you will be given a valid chunky string from which all the closing brackets have been removed. You must restore the brackets and return the original valid chunky string.

For example:

Input               Restored String
'x'                 'x'
'[xy'               '[xy]'
'[x[yy'             '[x[yy]]'
'[[xyy'             '[[xy]y]'
'[[ab[ab'           '[[ab][ab]]'
'[c[o[d[e[w[a[rs'   '[c[o[d[e[w[a[rs]]]]]]]'

In the tests all input strings will be valid chunky strings (with closing brackets removed).

Strings
Recursion

Stats:

CreatedAug 31, 2024
PublishedAug 31, 2024
Warriors Trained716
Total Skips27
Total Code Submissions952
Total Times Completed107
Python Completions54
JavaScript Completions46
C++ Completions26
Haskell Completions7
Total Stars23
% of votes with a positive feedback rating100% of 27
Total "Very Satisfied" Votes27
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes0
Total Rank Assessments9
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • Paul Robertson Avatar
  • JohanWiltink Avatar
  • dfhwze Avatar
  • o2001 Avatar
Ad