PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates proficiency in data validation, numeric robustness, error handling, aggregation, per-item cost computation and deterministic sorting within Python-based data manipulation tasks, and it belongs to the Data Manipulation (SQL/Python) domain.

  • medium
  • Stripe
  • Data Manipulation (SQL/Python)
  • Software Engineer

Compute costs with validation and sorting in Python

Company: Stripe

Role: Software Engineer

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Technical Screen

Implement a three-part Python task to compute costs for purchase line items. Part 1: Write compute_cost(line_items, price_db) where line_items is a list of dicts like {"product_id": str, "qty": int} and price_db is a dict mapping product_id -> unit_price (float). Return (total_cost, breakdown) where breakdown lists per-item cost. Clarify and implement behavior when a product_id is missing from price_db (e.g., raise, skip with warning, or default). Part 2: Add robust validation: quantities/prices must be numeric; qty must be nonnegative; reject NaN/inf; detect and report invalid rows with clear errors. Include tests for empty input, large values, and duplicate product_ids (define whether to sum or treat as separate lines). Part 3: If sort=True, return breakdown sorted by per-item cost descending using a lambda key; otherwise preserve input order. Ensure outputs match expected results and document rounding rules.

Quick Answer: This question evaluates proficiency in data validation, numeric robustness, error handling, aggregation, per-item cost computation and deterministic sorting within Python-based data manipulation tasks, and it belongs to the Data Manipulation (SQL/Python) domain.

Last updated: Mar 29, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Design an idempotent SQL ETL for late data - Stripe (medium)
  • Write SQL to monitor weekly chargeback spikes - Stripe (medium)
  • Write SQL to detect recurring non-subscription users - Stripe (medium)
  • Design metrics and write SQL for a case - Stripe (medium)
  • Write SQL for snapshot features and labels - Stripe (medium)