Skip to content
Decoder

Combination Sum IV

Medium

Problem

Given an array of distinct positive integers nums and a target, return how many ordered sequences of numbers from nums add up to target. Numbers may be used any number of times, and different orders count as different sequences.

Example 1

Input
nums = [1, 2, 3], target = 4
Output
7

Example 2

  (1,1,1,1) (1,1,2) (1,2,1) (2,1,1) (2,2) (1,3) (3,1)

Example 3

Input
nums = [9], target = 3
Output
0

Constraints

  • 1 <= nums.length <= 200
  • 1 <= nums[i] <= 1000
  • 1 <= target <= 1000
  • The answer fits in a 32-bit integer.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.