FastPrepInsert Addition and Multiplication Operators
Problems/Insert Addition and Multiplication Operators

Insert Addition and Multiplication Operators

Pinterest logoPinterest● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Pinterest onsite interview. The report keeps a list of integers as input, a choice of only + or * between them, a fixed element order, normal multiplication before addition in the follow-up, and returning every matching expression. We chose the function name, the nonnegative limits, the exact way to write each expression, the output order, and the examples, only so that the reported follow-up can run. Our version is about 95% the same as the reported follow-up.

You are given an integer array numbers and an integer target. Insert exactly one binary operator, either + or *, between every pair of adjacent array elements.

Evaluate each resulting expression using ordinary arithmetic precedence, so every multiplication is performed before addition. Return every expression whose value equals target.

  • Use every number exactly once and preserve the original order.
  • Do not concatenate adjacent numbers.
  • Write each number in its ordinary decimal form with no spaces around operators.
  • Return distinct expressions in ascending lexicographic order.

Function

findExpressions(numbers: int[], target: long) → String[]

Examples

Example 1

numbers = [1,2,3,4]target = 10return = ["1*2*3+4","1+2+3+4"]

Under normal precedence, both 1 * 2 * 3 + 4 and 1 + 2 + 3 + 4 equal 10. No other placement of the permitted operators does.

Example 2

numbers = [2,3,2]target = 8return = ["2*3+2","2+3*2"]

Multiplication is evaluated first, so both 2 * 3 + 2 and 2 + 3 * 2 equal 8.

Example 3

numbers = [0,5,0]target = 0return = ["0*5*0","0*5+0","0+5*0"]

Zero-valued multiplication groups create three different valid expressions. The result is sorted lexicographically.

Constraints

  • 2 <= numbers.length <= 15.
  • 0 <= numbers[i] <= 9.
  • 0 <= target <= 10^15.
  • Every complete expression value fits in a signed 64-bit integer under these bounds.

More Pinterest Onsite Interview questions

  • Minimum Bus Routes to a DestinationPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Delete and Compact a Forest SubtreePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Filter Pins by Excluded IDsONSITE INTERVIEW · Seen Oct 2026
  • Top-Scoring Items in a Time WindowONSITE INTERVIEW · Seen Oct 2026
  • Optimal Account BalancingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Escape Room LeaderboardPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Policy Violation Set ChecksONSITE INTERVIEW · Seen Sep 2026
  • Shortest Sequence of Source SubsequencesONSITE INTERVIEW · Seen Sep 2026
  • Unique Active Pins by Time SegmentONSITE INTERVIEW · Seen Sep 2026
  • Coin ChangeONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Maximum Unique-Character Word SubsetMeta · ONSITE INTERVIEWMeta interview questions
  • Word Break IIAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Word Break IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Word Search IIKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Largest Number Below N from Reusable DigitsByteDance · PHONE SCREENByteDance interview questions
  • Generate All Permutations of a NumberFleetx · ONSITE INTERVIEW
  • Rank Word-Translation Hints from Sentence TranslationsDuolingo · PHONE SCREEN · ONSITE INTERVIEWDuolingo interview questions
  • Group AnagramsAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Response Time Stats by URL PatternGusto · ONSITE INTERVIEWGusto interview questions

Pinterest interview experiences

  • Pinterest Experienced MLE Phone Screen: 1 Experience
All Pinterest interview questionsSee Pinterest hiring insights
Saved
class Solution {
    public String[] findExpressions(int[] numbers, long target) {
        // write your code here
    }
}
Checking account…