Tap here to switch tabs
Problem
Submissions

Problem: Transform Array Using Pair Operations

Transform Array Using Pair Operations asks whether one integer array can become a target array by repeatedly redistributing the sum of two distinct elements, allowing negative values.

Statement

You are given two integer arrays source and target, both of the same length.

In one operation, you can perform the following steps:

  • Choose two distinct indices i and j.

  • Choose any integer delta.

  • Update source[i] to source[i] + source[j] - delta.

  • Update source[j] to delta.

Return true if it is possible to transform source into target after applying any number of operations, or false otherwise.

Constraints:

  • 2≤2 \leq source.length == target.length ≤105\leq 10^5

  • −109≤-10^9 \leq source[i], target[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Transform Array Using Pair Operations

Transform Array Using Pair Operations asks whether one integer array can become a target array by repeatedly redistributing the sum of two distinct elements, allowing negative values.

Statement

You are given two integer arrays source and target, both of the same length.

In one operation, you can perform the following steps:

  • Choose two distinct indices i and j.

  • Choose any integer delta.

  • Update source[i] to source[i] + source[j] - delta.

  • Update source[j] to delta.

Return true if it is possible to transform source into target after applying any number of operations, or false otherwise.

Constraints:

  • 2≤2 \leq source.length == target.length ≤105\leq 10^5

  • −109≤-10^9 \leq source[i], target[i] ≤109\leq 10^9