Solve shipping capacity and expression insertion
Company: Meta
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Overview: This combined prompt evaluates algorithmic problem-solving skills: the first problem tests array partitioning and capacity planning under ordering and resource constraints, and the second tests combinatorial expression generation, tokenization, and numeric edge-case handling in digit strings.
Minimum Shipping Capacity
Constraints
- weights are positive
- 1 <= D <= len(weights)
Examples
Input: ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5)
Expected Output: 15
Explanation: Classic example.
Input: ([3, 2, 2, 4, 1, 4], 3)
Expected Output: 6
Explanation: Capacity 6 works.
Hints
- Binary-search capacity and greedily count how many days it needs.
Insert Plus or Minus to Hit Target
Constraints
- s contains digits
- multi-digit tokens cannot start with 0
Examples
Input: ('123', 6)
Expected Output: ['1+2+3']
Explanation: 1+2+3 hits 6.
Input: ('105', 5)
Expected Output: ['10-5']
Explanation: Concatenation is allowed without leading zero tokens.
Hints
- Backtrack over the next token, then add it with + or -.