Skip to content

Latest commit

 

History

History
13 lines (11 loc) · 536 Bytes

File metadata and controls

13 lines (11 loc) · 536 Bytes

Decode a String that has pattern [n|string] -> n number of the string. [3|ABC] -> ABCABCABC.
HG[3|B[2|CA]]F
HGBCACABCACABCACAF

We can use recursion to solve the problem. When we encounter a '[' we can go into the next subarray and when we meet a ']' we can calculate the decoded substring with in this the [...].

		      HG[   BCACABCACABCACA F
			  /      ^
			 /       |
		  3|B[     CACA]
	      /         ^
	     /          |
	  2|CA] ->    CACA

time: O(n) - n is the length of the whole string
space: O(depth)