← Problems63. Position based revenue attributionHardPython
00:00 / 40:00

Position based revenue attribution

HardNot attempted yetAsked at Adobe

Finance splits each conversion's revenue across the channels that touched it, using a position-based model. The split has to reconcile to the penny — the credited cents for a conversion must add up to its revenue exactly, with no rounding drift anywhere in the report.

Input schema

solve(journeys: list[dict]) -> list[dict]

Each journey has conversion_id (int), revenue_cents (int) and channels, the touched channels in chronological order.

Return one dict per conversion and channel, with keys in this order:

conversion_id, channel, credit_cents

Constraints

  • One touch takes 100%; two touches split 50/50
  • Three or more: the first takes 40%, the last takes 40%, and the remaining 20% is split equally between every touch in between
  • Credit is earned per position — a channel touched twice earns twice, and the two are summed
  • credit_cents are integers and must sum to revenue_cents exactly for each conversion
  • Give each position the whole-cent part of its exact share, then hand out the leftover cents one at a time, largest fractional part first, ties going to the earlier position
  • One row per distinct channel in the journey, including a channel credited 0
  • Order by conversion_id, then channel
  • Up to 3,000,000 journeys

Example 1one touch, then an even two way split

Input · journeys
channelsconversion_idrevenue_cents
["email"]110000
["email","social"]210000
Output
conversion_idchannelcredit_cents
1email10000
2email5000
2social5000

Example 2four touches, forty twenty forty

Input · journeys
channelsconversion_idrevenue_cents
["search","display","social","email"]310000
Output
conversion_idchannelcredit_cents
3display1000
3email4000
3search4000
3social1000

Topics

attributiondata structures

Similar problems

Community-reported interview topic. Not an official company question and no affiliation is implied.

solution.py
Loading editor…
Draft not saved yet · Spaces 4 · UTF-8⌘↵ run ⌘⇧↵ submit
Nothing run yet

Run against the public tests, or submit to score against all of them.