FastPrepMath with Lego Blocks
Problems/Math with Lego Blocks

Math with Lego Blocks

Patreon logoPatreon● MediumNEW GRADOA

Updated Dec 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A new-graduate candidate with a bachelor's degree, applying through a referral for a full-time software engineering role at Patreon, posted screenshots of the online assessment on 2023-04-20. This task was the second of three questions, and the screenshot gives it in full. Two rows of Lego blocks carry positive numbers, a block whose number is lost shows 0, every 0 has to become a positive number so that both rows add up to the same amount, and the goal is the smallest amount that works, or -1 when nothing works. The screenshot walks through one pair of rows that both reach 6, which we keep as Example 1, and lists the limits we use: up to 10^5 blocks per row, each showing a value from 0 to 10^4. There the function is called findMinimumEqualSum and receives the rows as lists of integers. The poster rated the experience neutral and the difficulty average. Our choices: the function is named minSum, the usual name for this well-known task, receives the rows as integer arrays nums1 and nums2 in that order, and returns the amount as a 64-bit integer; Examples 2 and 3 are ours.

A teacher sets out two rows of Lego blocks for a math lesson. The first row is the array nums1 of length n, and the second row is the array nums2 of length m. Each block is meant to carry a positive integer, but some numbers have gone missing; a block with a missing number shows 0. A row may have no missing numbers at all.

The students must write a positive integer on every block that shows 0, picking the numbers so that the blocks of nums1 add up to the same total as the blocks of nums2. Different blocks may get different numbers.

Return the smallest total the two rows can share once every 0 has been filled in. If no choice of numbers can make the two totals match, return -1.

Function

minSum(nums1: int[], nums2: int[]) → long

Examples

Example 1

nums1 = [1, 0, 2]nums2 = [1, 3, 0, 0]return = 6

Counting each 0 as 1, nums1 adds up to at least 4 and nums2 to at least 6. Writing 3 on the blank block of nums1 and 1 on both blank blocks of nums2 gives [1, 3, 2] and [1, 3, 1, 1], which both add up to 6. No smaller shared total exists, because nums2 never adds up to less than 6.

Example 2

nums1 = [5, 0, 0]nums2 = [3, 2]return = -1

The two blank blocks of nums1 get at least 1 each, so nums1 adds up to at least 7. nums2 has no blank block, so its total stays 5. Since nums1 can never drop to 5, the totals cannot match.

Example 3

nums1 = [0, 7]nums2 = [2, 0, 1, 0]return = 8

nums1 adds up to at least 8 and nums2 to at least 5. Writing 1 on the blank block of nums1 and 1 and 4 on the blank blocks of nums2 gives [1, 7] and [2, 1, 1, 4], which both add up to 8.

Constraints

  • 1 <= n == nums1.length <= 105
  • 1 <= m == nums2.length <= 105
  • 0 <= nums1[i], nums2[j] <= 104

More Patreon interview questions

  • Three SumOA · Seen Apr 2025
  • Make Layer Times OddOA · Seen Oct 2024
  • Sum of Subarray RegionsOA · Seen Oct 2024
  • Binary Cardinality SortingOA · Seen Apr 2023
  • Closest NumbersOA · Seen Apr 2023
  • Maximum Books From BundlesOA · Seen Apr 2023
  • Professors Teaching Outside Their DepartmentOA · Seen Apr 2023
  • Botany QueryOA · Seen Apr 2023
  • Sliding-Window API Rate LimiterPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Employee Importance from a DictionaryPHONE 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
All Patreon interview questionsSee Patreon hiring insights
Saved
class Solution {
    public long minSum(int[] nums1, int[] nums2) {
        // Write your code here.
    }
}
Checking account…