Interview Questions/Coding/Apartment Bundle Planner

Apartment Bundle Planner

Preview mode. Log in to edit, run, submit, and save progress.

Medium

Apartment Bundle Planner

A builder sells apartment bundles of exactly 3, 5, or 7 units. For each requested total n, print counts a, b, and c for 3-unit, 5-unit, and 7-unit bundles. The total 3*a + 5*b + 7*c must equal n. If several plans are possible, the audit format prefers the smallest b, and if still tied, the smallest c. If no non-negative plan exists, print -1. Input Format: The first line contains t, the number of test cases. Each test case contains n. Output Format: For each test case, print a b c for the selected plan, or -1 if no plan exists.

Examples

Example 1
Input:
1
30
Output:
10 0 0

Explanation: Ten 3-unit bundles make exactly 30 units, with no 5-unit or 7-unit bundles needed.

Approach hint

Start with the simplest clear approach, explain the trade-off, then move toward the cleaner answer.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

solution.cpp