Example 1
RunLengthEncoding()
getEncodedList(characters = ["A", "B", "B", "C", "A"]) returns ["A,1", "B,2", "C,1", "A,1"]
get(compressedString = "A:1|B:2|C:1|A:1", i = 2) returns "B"
Explanation:
The compressed string represents ["A", "B", "B", "C", "A"]. Index 2 contains "B".
Example 2
RunLengthEncoding()
getEncodedList(characters = ["A", "A", "A", "A"]) returns ["A,4"]
get(compressedString = "A:4", i = 0) returns "A"
get(compressedString = "A:4", i = 3) returns "A"
get(compressedString = "A:4", i = 4) returns ""
Explanation:
The compressed string represents four characters. Indices 0 through 3 are valid, and index 4 is invalid.
Example 3
RunLengthEncoding()
getEncodedList(characters = ["A", "A", "B", "B", "B", "C", "C", "A"]) returns ["A,2", "B,3", "C,2", "A,1"]
get(compressedString = "A:2|B:3|C:2|A:1", i = 4) returns "B"
get(compressedString = "A:2|B:3|C:2|A:1", i = 6) returns "C"
get(compressedString = "A:2|B:3|C:2|A:1", i = 7) returns "A"
Explanation:
The first two "A" values form one group. The last "A" appears after "C", so it forms a separate group.
Example 4
RunLengthEncoding()
getEncodedList(characters = []) returns []
get(compressedString = "", i = 0) returns ""
get(compressedString = "", i = -1) returns ""
Explanation:
An empty compressed string represents an empty original list, so every index is invalid.
Example 5
RunLengthEncoding()
getEncodedList(characters = ["X", "Y", "Y", "Y", "Z"]) returns ["X,1", "Y,3", "Z,1"]
get(compressedString = "M:2|N:5|P:1", i = 6) returns "N"
Explanation:
The compressed string passed to get is independent from the characters passed to getEncodedList. In "M:2|N:5|P:1", index 6 contains "N".