Quick Overview

Allocate an annual revenue amount in cents evenly across twelve months without floating-point arithmetic. Preserve the total exactly and assign any remainder to the earliest months.

Distribute Annual Revenue Across Twelve Months

Company: Rillet

Role: Backend Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

# Distribute Annual Revenue Across Twelve Months Implement `distribute_revenue(annual_cents)`. The input is a non-negative integer amount of annual revenue measured in cents. Return a list of exactly 12 integers representing the monthly revenue allocations. The allocations must sum to `annual_cents` and be as even as possible: the difference between any two months may not exceed one cent. If the amount is not divisible by 12, assign the extra cents to the earliest months. Do not use floating-point arithmetic. ## Examples - `distribute_revenue(1200)` returns `[100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100]`. - `distribute_revenue(14)` returns `[2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]`. - `distribute_revenue(0)` returns twelve zeroes. ## Constraints - `0 <= annual_cents <= 10**18` - The input is an integer.

Quick Answer: Allocate an annual revenue amount in cents evenly across twelve months without floating-point arithmetic. Preserve the total exactly and assign any remainder to the earliest months.

Implement distribute_revenue(annual_cents). For cross-language exactness, annual_cents is a canonical non-negative decimal string: exactly '0', or a first digit from 1 through 9 followed by zero or more digits. Return exactly 12 strings in that same canonical form. Their integer values must sum to the annual amount, differ by at most one, and place any extra cents in the earliest months.

Constraints

  • annual_cents represents a value from 0 through 10^18 and is exactly '0' or matches [1-9][0-9]*.
  • Every returned element is exactly '0' or matches [1-9][0-9]*; leading zeroes are forbidden.
  • Return exactly 12 decimal strings and do not use floating-point arithmetic.

Examples

Input: ('0',)

Expected Output: ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0']

Explanation: Checks exact quotient, remainder, and earliest-month allocation.

Input: ('1',)

Expected Output: ['1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0']

Explanation: Checks exact quotient, remainder, and earliest-month allocation.

Hints

  1. Divide the annual amount by 12 into a quotient and remainder.
  2. The first remainder months receive quotient + 1.

Loading coding console...