Company: Wells Fargo
Difficulty: medium
Sum of Compressed Numbers You are given an array a of size n . The compressed version of an array is obtained by replacing every block of consecutive equal integers with a single occurrence of that integer. For example, for a = [1, 1, 2, 2, 1, 1] the compressed version is [1, 2, 1] . The compressed number of an array is the number of ways to remove a non-empty set of indexes from the array so that what remains is exactly the compressed version of the array. Two ways are considered different if the set of indexes deleted is different; the order in which the indexes are removed does not matter. In particular, an array that is already equal to its own compressed version has compressed number 0 , because at least one index has to be deleted. Calculate the sum of the compressed numbers of all subarrays of a . Since the sum may be large, return it modulo 10^9 + 7 . A subarray is a contiguous, non-empty block of the array. Function sumOfCompressedNumbers(a: int[]) -> int Complete the funct