Google | Phone Screen | Dot Product Closest to a Target
Anonymous User
809

Given an array of integers and target value, return the output comprising of 0's and 1's such that largest dot product (of input and the output) is equal or less than target value.

Example 1:

Input: [1, 2, 2, 1], target = 4
Output: [0, 1, 1, 0]

Example 2:

Input: [1, 2, 2, 1], target = 3
Output: [1, 1, 0, 0] or [1, 0, 1, 0]

IF there are more than 1 output satisfying, return any one of the possible outputs.
i.e. input.result != target then choose result s.t (target - input.result) is minimum.

Comments (7)