Count Plus and Minus Sign Patterns
Updated
Problem statement
You are given an integer array nums and an integer target. Put a plus sign or a minus sign in front of every number of nums, then add up all the signed numbers.
Return how many of the possible sign choices give a total equal to target. Every number gets its own sign, so for a 0 the plus and minus choices count as two different choices.
Function
countSignWays(nums: int[], target: int) → intExamples
Example 1
nums = [3,1,2]target = 0return = 2The signs must split the numbers into two groups with equal sums. +3 -1 -2 and -3 +1 +2 both give 0, and no other choice does, so the answer is 2.
Example 2
nums = [2,0,4]target = 6return = 2Both 2 and 4 must get a plus sign. The 0 can take either sign without changing the total, so there are 2 choices: +2 +0 +4 and +2 -0 +4.
Example 3
nums = [5,5]target = 3return = 0The possible totals are 10, 0 and -10. None of them is 3, so the answer is 0.
Constraints
1 <= nums.length <= 200 <= nums[i] <= 10000 <= sum(nums) <= 1000-1000 <= target <= 1000
More Adobe Phone Screen questions
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
- All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
- Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
- Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
- Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
- Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- Winning Draws for a Mahjong HandZip · PHONE SCREENZip interview questions
- Word Break IIAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Word Break IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Count Complete Tic-Tac-Toe GamesDecagon · PHONE SCREEN · ONSITE INTERVIEWDecagon interview questions
- Longest Increasing SubsequenceByteDance · PHONE SCREENByteDance interview questions
- Jump GamePaytm · PHONE SCREENPaytm interview questions
- Query Words Within K PositionsPalantir · PHONE SCREENPalantir interview questions
- House RobberVisa · PHONE SCREENVisa interview questions
- SubsetsTemu · PHONE SCREENTemu interview questions
- Longest Increasing SubsequenceAngel One · PHONE SCREEN
Interview reports that mention this question
Adobe interview experiences
- Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
- Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
- Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
- Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)
- Adobe Product Intern Interviews: 15 Experiences (Part 3 of 4)