Reported July 2026
Amazonhash table

Domain Weight Calculation

Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Amazon OA. Under 2s to a working solution.
Founder's read

Amazon reported this one in July 2026, and it looks like string parsing but it's really a suffix tree problem in disguise. Each domain is a node, its parent is the same name minus the first label, and you want the root-to-leaf sums for every leaf. If your OA invite is sitting in your inbox, this is a hash map plus a sort, nothing exotic. The trap is in the leaf definition and the output format. Read it twice before you type. If you blank on the day, StealthCoder runs invisibly during the live assessment and can hand you the approach so you don't burn your clock.

The problem

You are given an array of strings domainScores. Each string has this format:
domain score
domain is a dot-separated domain name, and score is an integer weight assigned directly to that domain.
For every leaf domain, compute its total score. A domain is a leaf domain if it appears in domainScores and no other input domain has it as a suffix child.
The total score of a leaf domain is the sum of the scores assigned to that domain and all of its suffix ancestors that appear in the input.
For example, the suffix ancestors of mail.domain.com are domain.com and com.
Return one string for each leaf domain in lexicographic order. Each output string should have this format:
domain=totalScore
What the interview report shared
The interview report described a domain-score task: every domain has its own score, and the candidate had to output each leaf domain's accumulated score. The report included an example where mail.domain.com accumulated scores from mail.domain.com, domain.com, and com, and contact.user.test.com accumulated scores from all of its suffix ancestors. The report did not specify the function signature, constraints, or output ordering.
How FastPrep adapted it
FastPrep turned that report into a runnable practice problem by using an array of "domain score" strings as input and returning sorted "domain=score" strings. The lexicographic ordering rule and additional examples are practice scaffolding based on the reported task, not exact original wording.

Function
calculateDomainScores(domainScores: String[]) → String[]

Examples
Example 1
domainScores = ["com 20", "domain.com 10", "mail.domain.com 5", "test.com 10", "user.test.com 30", "contact.user.test.com -5"]
return = ["contact.user.test.com=55", "mail.domain.com=35"]
mail.domain.com is a leaf, and its total is 5 + 10 + 20 = 35.
contact.user.test.com is also a leaf, and its total is -5 + 30 + 10 + 20 = 55.
Example 2
domainScores = ["com 5", "a.com 2", "b.com 3"]
return = ["a.com=7", "b.com=8"]
a.com and b.com are leaves. Both include the score of their suffix ancestor com.
Example 3
domainScores = ["api.shop.com 4", "shop.com -2", "com 1", "cdn.shop.com 7", "img.cdn.shop.com 3"]
return = ["api.shop.com=3", "img.cdn.shop.com=9"]
cdn.shop.com is not a leaf because img.cdn.shop.com is one of its suffix children.

Constraints
1 <= domainScores.length <= 100000
Each input string contains exactly one domain and one integer score separated by one space.
Domain names contain lowercase English letters and dots.
Each domain label has length at least 1.
Each domain appears at most once.
-10^9 <= score <= 10^9
The sum of all domain string lengths is at most 300000.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Store every domain and its score in a hash map. For each domain, the parent is everything after the first dot. Mark a domain as non-leaf if it's the parent of any other input domain. Then for each leaf, walk up the parent chain, adding scores that exist in the map. Skipped ancestors contribute nothing, since only domains in the input count. Sum can reach 10^9 times many labels, so use 64-bit integers. Sort the final strings lexicographically, not by score. The pitfall is checking leaf status by scanning all domains, which goes quadratic at 100000 entries. Build a set of parents in one pass instead. Cost is bounded by total string length, 300000, plus the sort. Memoizing each domain's accumulated total from its parent avoids repeated walks. StealthCoder is your hedge in the live OA if the parent-set idea doesn't come to you under pressure.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Domain Weight Calculation cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Amazon's OA.

Amazon reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Domain Weight Calculation FAQ

What's the trick in the Amazon Domain Weight Calculation problem?+

Treat each domain as a node whose parent is the name with the first label removed. Build a set of all parents to find leaves, then sum scores up the parent chain using a hash map. It's a tree in disguise, solved with hashing and a final sort.

How do I define a leaf domain correctly?+

A leaf is a domain in the input that no other input domain has as its suffix parent. Compute every domain's immediate parent once, put them in a set, and any domain not in that set is a leaf. Don't scan pairs of domains.

Do ancestors missing from the input count?+

No. Only ancestors that appear in domainScores add to the total. In example 3, shop.com and com exist, so they count. If an intermediate ancestor were absent, you'd skip it and keep walking up to the next one that exists.

What complexity should I aim for with 100000 domains?+

Roughly linear in total string length, about 300000 characters, plus an n log n sort of the output. Avoid quadratic leaf checks. Memoizing each domain's accumulated total from its parent keeps chain walks from repeating, though plain walking is fine given the length bound.

What edge cases break most solutions?+

Negative scores, sums that overflow 32-bit ints, and sorting by score instead of lexicographically by the full output string. Also a single-label domain like com that is itself a leaf when nothing else is under it. Test that case first.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Amazon.

OA at Amazon?
Invisible during screen share
Get it