FastPrepSum of Compressed Number for All Subarrays
Problems/Sum of Compressed Number for All Subarrays

Sum of Compressed Number for All Subarrays

Wells Fargo logoWells Fargo● HardFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given an array a of size n. The compressed version of an array is defined as replacing the occurrence of consecutive equal integers with the single occurrence.

Example: For a = [1, 1, 2, 2, 1, 1], the compressed version will be [1, 2, 1].

The compressed number of an array is defined as the number of ways to remove some non-empty subsequence of indexes from the initial array to make it compressed. Two ways are considered different if the sequence of indexes deleted from the array was different, the order of removing does not matter.

Calculate the sum of compressed number for all subarrays of the array a. Since the sum may be large, print it modulo 10^9 + 7.

Function

sumOfCompressedNumbers(a: int[]) → int

Complete the function sumOfCompressedNumbers in the editor.

sumOfCompressedNumbers has the following parameter:

  1. int a[n]: an array of integers

Returns int: the sum of compressed number for all the subarrays of the array a modulo 10^9 + 7

Examples

Example 1

a = [6, 7, 3, 6, 6]return = 8

We have a = [6, 7, 3, 6, 6]. The subarrays of a with their respective compressed numbers are as follows:

  • [6] has compressed number 0 as it is already compressed.
  • Similarly, [6, 7], [6, 7, 3], [6, 7, 3, 6] have compressed number 0 as they are already compressed.
  • [6, 7, 3, 6, 6] has compressed number 2 as we can delete either index 4 or index 5 to get compressed version [6, 7, 3, 6].
  • [7], [7, 3], [7, 3, 6] have compressed number 0 as they are already compressed.
  • [7, 3, 6, 6] has compressed number 2.
  • [3], [3, 6] have compressed number 0 as they are already compressed.
  • [3, 6, 6] has compressed number 2.
  • [6] has compressed number 0 as it is already compressed.
  • [6, 6] has compressed number 2.
  • [6] has compressed number 0 as it is already compressed.

So, the total sum of all compressed numbers of all subarrays of a = 8.

Example 2

a = [4, 4]return = 2

We have a = [4, 4]. The subarrays of a with their respective compressed numbers are as follows:

  • [4] has compressed number 0 as it is already compressed.
  • [4, 4] has compressed number 2 as we can delete either index 1 or index 2 to get compressed version [4].

So, the sum of compressed number = 2.

Example 3

a = [3, 3, 3, 3]return = 16

There are 4 subarrays of type . The compressed number is 0 as it is already compressed. There are 3 subarrays of type . The compressed number is 2 as either of the index can be deleted. So, the sum of compressed number would be 6. There are 2 subarrays of type . the compressed number is 3 as either of the sequence of indices or can be deleted. So, the sum of compressed number would be 6. There is 1 subarray with the compressed number 4. So, the sum of compressed number of all subarrays is 16.

Constraints

  • 1 ≤ t ≤ 10
  • 1 ≤ n ≤ 10^5
  • 1 ≤ a[i] ≤ 10^5

More Wells Fargo interview questions

  • Server Upgrade PlanningOA · Seen Nov 2026
  • Student and Course EnrollmentOA · Seen Nov 2026
  • Bond Interest Summary Above 3%OA · Seen Oct 2026
  • Count Phrases Formed by Anagram ReplacementOA · Seen Oct 2026
  • Event Statistics AggregatorOA · Seen Sep 2026
  • Ordered Deployment Configuration ValidatorOA · Seen Sep 2026
  • Longest Subsequence That Is a SubstringOA · Seen Jul 2026
  • Overloaded Game Account InventoriesOA · Seen Jul 2026
  • Count Server ReplacementsOA · PHONE SCREEN · Seen Feb 2026
  • Minimum Remaining LengthOA · PHONE SCREEN · Seen Feb 2026

Similar questions at other companies

  • Optimize Discount Selection Under a Point BudgetPalantir · OAPalantir interview questions
  • Pressure-Isolation Shutdown OrderIntuit · OAIntuit interview questions
  • Count Permutations Without Three Equal Parities in a RowGoogle · OAGoogle interview questions
  • Count Good SubsequencesFlexport · OAFlexport interview questions
  • Count Perfect BreaksAtlassian · OAAtlassian interview questions
  • Count Strictly Increasing Subsequences of Length 3IBM · OAIBM interview questions
  • Winning Draws for a Mahjong HandZip · PHONE SCREENZip interview questions
  • Coin Change IIApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
  • Magic Number Range CounterGraviton · OA
  • At Most K Jumps with Quadratic Transition CostInfosys · OAInfosys interview questions

Interview reports that mention this question

  • Wells Fargo OA: What It Tests (2026)

Wells Fargo interview experiences

  • Wells Fargo SWE Intern OA and Interview Questions: 18 Experiences
All Wells Fargo interview questionsSee Wells Fargo hiring insights
Saved
class Solution {
    public int sumOfCompressedNumbers(int[] a) {
      // write your code here
    }

}
Checking account…