FastPrepDomain Weight Calculation
Problems/Domain Weight Calculation

Domain Weight Calculation

Amazon logoAmazon● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This came from a real onsite interview report. The original report shared the core domain-score task and a concrete example, and FastPrep filled in the runnable function format, ordering rule, and extra practice examples so you can try it here. Estimated match rate: 90% for the core task, 75% for interface and examples, and 35% for exact original wording. If you find a fuller version, feel free to let us know and we will update it.

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

Worked example

Every domain has its own score, and the task is to output each leaf domain's accumulated score. For example, mail.domain.com accumulates scores from mail.domain.com, domain.com, and com, and contact.user.test.com accumulates scores from all of its suffix ancestors.

Input and output

The input is an array of "domain score" strings, and the output is the sorted "domain=score" strings.

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.

More Amazon Onsite Interview questions

  • Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Cheapest Flights Within K StopsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Dungeon GameONSITE INTERVIEW · Seen Nov 2026
  • Integer BreakONSITE INTERVIEW · Seen Nov 2026
  • LFU CacheONSITE INTERVIEW · Seen Nov 2026
  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Feature Flags with Rules, Dependencies and ExposurePerplexity AI · ONSITE INTERVIEWPerplexity AI interview questions
  • Template Variable ExpansionGoogle · ONSITE INTERVIEWGoogle interview questions
  • JSON Path Lookup with Implicit Array WildcardsMongoDB · ONSITE INTERVIEWMongoDB interview questions
  • Transform Dotted Keys into a Nested MapProofpoint · ONSITE INTERVIEW
  • Longest-Match Tokenizer with Unknown SymbolsAnthropic · ONSITE INTERVIEWAnthropic interview questions
  • Filesystem Hash TreeCursor · PHONE SCREEN · ONSITE INTERVIEWCursor interview questions
  • In-Memory Directory and File OperationsSquarepoint Capital · ONSITE INTERVIEWSquarepoint Capital interview questions
  • File System PathsCapital One · ONSITE INTERVIEWCapital One interview questions
  • Nested Template Variable ExpansionFigma · ONSITE INTERVIEWFigma interview questions
  • Highlight and Rank Overlapping CitationsHarvey · ONSITE INTERVIEWHarvey interview questions

Amazon interview experiences

  • Amazon SWE OA with AI Coding: 1 Experience
  • Amazon SWE Intern Phone Screen Interview Experience: 1 Experience
  • Amazon New Grad SDE I OA and Virtual Onsite: 1 Experience
  • Amazon BIE Intern SQL and Interview Questions: 17 Experiences
  • Amazon Experienced SWE AI-Assisted Debugging OA: 1 Experience
  • Amazon SDE II (L5) Interview Questions: 5 Experiences
See Amazon hiring insights
Saved
class Solution {
    public String[] calculateDomainScores(String[] domainScores) {
      // write your code here
    }

}
Checking account…