Two Pointers for a Linear Solution V
Yet another hot-off-the-press problem requiring a two-pointers approach. Keep track of a pointer for the encoded1 and one for encoded2. As you traverse the arrays, make a decision on which one to add, and how to add, based on the equality or inequality of the frequencies. At that point, change the frequency of the "larger" array. When you add to the output list, just make sure to check against the "tail" of the list for the same frequency, in which case, merge them. Code is down below, cheers, ACC. Product of Two Run-Length Encoded Arrays - LeetCode 1868. Product of Two Run-Length Encoded Arrays Medium 3 0 Add to List Share Run-length encoding is a compression algorithm that allows for an integer array nums with many segments of consecutive repeated numbers to be represented by a (generally smaller) 2D array encoded . Each encoded[i] = [val i , freq i ] describes the i th segment of repeated numbers in nums whe...