Count Sign Assignments So Bid Adjustments Net to a Target

Last updated: November 29, 2026

Quick Overview

A campaign has a list of bid adjustment amounts, and each must be applied as either an increase or a decrease. Count the sign assignments whose net change equals a target T.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


A campaign has a list of bid adjustment amounts, and each must be applied as either an increase or a decrease. Count the sign assignments whose net change equals a target T.

This is target sum in a Google Ads framing. Interviewers check whether you can turn a signs problem into a subset-sum count with algebra, which shrinks the state from a range of signed totals to a single non-negative target.

What the Interviewer Expects
  • Derive the subset-sum reduction from P - N = T and P + N = S
  • Reject targets with the wrong parity or magnitude
  • Count subsets with a 1D table iterated downward
  • Handle zeros, which double the count
  • Compare with the direct offset-indexed DP
Key Topics to Cover
1D dynamic programming
Subset sum counting
Algebraic reduction
0/1 knapsack
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Return one valid assignment.
  • Adjustments can be applied as +, -, or skipped. What changes?
  • Values are large but few. What approach fits?
  • Find the assignment that gets closest to T.
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: list adj of non-negative integers and integer T. Assign + or - to each, count assignments with signed sum T. Each element must receive a sign, including zeros, so a 0 contributes two assignme...

High-Level Design

Let P be the sum of elements marked + and N the sum marked -. Then P - N = T and P + N = S (total). So P = (S + T) / 2. If S + T is odd or |T| > S, the answer is 0. Otherwise count subsets with sum P ...


Submit Your Answer
Markdown supported