Look Up Duty Rates by Most Specific HS Code Prefix

Last updated: November 29, 2026

Quick Overview

Duty rates are published for Harmonized System code prefixes of different lengths, and the most specific matching prefix applies. Build a structure that returns the applicable rate for a full 10-digit HTS code and compute total duty for a commercial invoice.

Flexport
Coding & Algorithms
Software Engineer
Flexport
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Duty rates are published for Harmonized System code prefixes of different lengths, and the most specific matching prefix applies. Build a structure that returns the applicable rate for a full 10-digit HTS code and compute total duty for a commercial invoice.

Flexport files customs entries, and every invoice line has to map to a tariff classification and a duty rate. The interviewer is checking that you recognize longest-prefix matching, pick a trie or an equivalent, and treat money and missing rates with care.

What the Interviewer Expects
  • Normalize codes by stripping dots and validating digits
  • Recognize longest-prefix match and implement it with a trie or a prefix hash
  • Return which prefix matched, for auditability
  • Raise on lines with no applicable rate instead of assuming zero
  • Discuss additional duties layered on top of the base rate
Key Topics to Cover
Trie
Longest Prefix Match
Customs Classification
Money Handling
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Section 301 tariffs add extra duty for some origin countries. How would you model rate layers?
  • Rates change on effective dates. How would you look up the rate in force on the entry date?
  • Compare the trie to a dictionary keyed by every prefix length. When is each better?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

add_rate(prefix, rate) stores an ad valorem rate for a code prefix such as 6109 or 61091000. lookup(code) accepts a code like 6109.10.0012 and returns the rate of the longest stored prefix p...

High-Level Design

A trie over digits fits naturally: walk the code digit by digit and remember the last node that carried a rate. HS codes are at most 10 digits, so lookups are effectively constant time. An alternative...


Submit Your Answer
Markdown supported

Related Questions