Count Products per Browse Node From a Multi-Valued Column

Last updated: November 29, 2026

Quick Overview

Each product row stores its browse node IDs as a pipe-separated string (asin, browse_nodes). Using pandas, count how many distinct products sit in each browse node, attach node names from a lookup table, and handle blanks, whitespace and repeated IDs.

Amazon
Data Manipulation (SQL/Python)
Data Scientist
Amazon
November 29, 2026
Data Scientist
Online Assessment
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


Each product row stores its browse node IDs as a pipe-separated string (asin, browse_nodes). Using pandas, count how many distinct products sit in each browse node, attach node names from a lookup table, and handle blanks, whitespace and repeated IDs.

Amazon's catalog places each ASIN in one or more browse nodes that drive category navigation, so analysts frequently need per-node counts from denormalized exports. Online assessments use this to check explode, string cleanup and a safe left join to a lookup table.

What the Interviewer Expects
  • Split the string and explode to one row per product and node
  • Strip whitespace and drop empty tokens
  • Deduplicate repeated node IDs per product before counting
  • Align key types (string vs integer) before merging with the lookup
  • Keep nodes missing from the lookup visible with a placeholder name
Key Topics to Cover
explode
string splitting
multi-valued columns
merge key types
pandas
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you roll counts up the browse node tree to parent categories?
  • How would you find products assigned to no browse node at all?
  • What if a product is in hundreds of nodes; would explode still be fine?
  • How would you do the same split and count in SQL?
Sharpen Your Skills on Codemia

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

Practice SQL Problems
Sample Answer
Clarify the Data
  • products(asin, browse_nodes): browse_nodes like "101|202", sometimes with spaces, duplicates, a trailing pipe, or NULL.
  • node_names(node_id, node_name): node IDs stored as integers in the l...
Approach
  1. Replace NULL with an empty string and split on |, giving a list per row.
  2. explode the list into rows, strip whitespace, drop empty tokens.
  3. Drop duplicate (asin, node_id) pairs so a produ...

Submit Your Answer
Markdown supported