FastPrepCompressing Array
Problems/Compressing Array

Compressing Array

Wells Fargo logoWells Fargo● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given an array of positive integers a and an integer k. In one operation you pick two numbers that sit next to each other and replace them with their product. You may do this only when the product is at most k.

You can do any number of operations. Return the smallest length the array can reach.

Complete the function getMinLength in the editor.

getMinLength has the following parameters:

  • int[] a: the array
  • int k: the largest product an operation may make

The function returns an int: the smallest length of the array after any number of operations.

Function

getMinLength(a: int[], k: int) → int

Examples

Example 1

a = [2, 3, 3, 7, 3, 5]k = 20return = 3

With a = [2, 3, 3, 7, 3, 5] and k = 20, these operations give the shortest array (positions start at 1):

  • Merge positions 1 and 2. The array becomes [6, 3, 7, 3, 5].
  • Merge positions 1 and 2 again. The array becomes [18, 7, 3, 5].
  • Merge positions 3 and 4. The array becomes [18, 7, 15].

No more merges are possible, because 18 · 7, 7 · 15 and 18 · 15 are all over 20. The answer is 3.

Constraints

  • 1 ≤ a.length ≤ 105
  • 1 ≤ a[i] ≤ 109
  • 1 ≤ k ≤ 109

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

  • Minimum Non-Adjacent Selection CapabilityMicrosoft · OAMicrosoft interview questions
  • Earn the Most 🐝Capital One · OACapital One interview questions
  • Minimum Cost to Merge Values into OnePayPal · OAPayPal interview questions
  • Minimum Operations to Sort with Rotations Then SwapsBank of New York Mellon · OA
  • Minimum Cost of Left and Right PropagationAmazon · OA
  • Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
  • Reschedule Meetings for Maximum Free TimeFivetran · OAFivetran interview questions
  • Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
  • Maximum ScoreNVIDIA · OANVIDIA interview questions
  • Maximum Distinct Values After Unit AdjustmentsBirla Pivot · OA

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 getMinLength(int[] a, int k) {
      // write your code here
    }

}
Checking account…