Encode and Decode Strings Visualizer & Solution | Rulcode
Loading problem details...
123. Encode and Decode Strings
PRO
Medium
Topics
Companies
Hint
Understand Before Coding
Loading visualization...
Visualize This Problem
Open Visualizer
Draw Your Approach
Draw
Example 1:
Input:strs = ["lint", "code", "love", "you"]
Output:["lint", "code", "love", "you"]
Explanation:The `encode` function converts the input array into '4#lint4#code4#love3#you'. The `decode` function then reconstructs the original array from this encoded string.
Example 2:
Input:strs = ["we", "say", ":", "yes"]
Output:["we", "say", ":", "yes"]
Explanation:The encoded string is '2#we3#say1#:3#yes', which is correctly decoded back to the original list.
Example 3:
Input:strs = ["", ""]
Output:["", ""]
Explanation:Empty strings are handled correctly; the encoded string becomes '0##0##', which decodes back into an array of two empty strings.
Example 4:
Input:strs = []
Output:[]
Explanation:If the input array is empty, the encoded string is an empty string, which decodes back into an empty array.
Example 5:
Input:strs = ["hello world", "!"]
Output:["hello world", "!"]
Explanation:The encoded string is '11#hello world1#!', and decoding it returns the initial list.