Problem Description
Given an integer array representing a run-length encoded list where each pair of adjacent elements [freq, val] represents freq occurrences of val, decompress the list by expanding each pair into a sublist of repeated values and concatenating these sublists.
Key Insights
- The input array always contains pairs, so iterate over it two elements at a time.
- For each pair [freq, val], generate a sublist with freq copies of val.
- Concatenate these sublists to form the final decompressed list.
- The problem requires only simple iteration and replication.
Space and Time Complexity
Time Complexity: O(n) where n is the total number of elements in the decompressed list (i.e., the sum of all frequency values). Space Complexity: O(n) for storing the output list.
Solution
Use a single pass through the input array by iterating over its indices in steps of two. For each pair, use multiplication of an array (or equivalent in your language) to replicate the value freq times. Append or concatenate the resulting list of values to a results container. The approach leverages basic array operations without requiring additional complex data structures.