PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

Scale ingredient strings by multiplying each leading integer quantity by a serving count while preserving unit, multiword name, and input order. Split only enough fields to isolate the quantity and unit, return a new list, and handle zero servings exactly.

  • easy
  • Upstart
  • Coding & Algorithms
  • Software Engineer

Scale Ingredient Quantities

Company: Upstart

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Take-home Project

# Scale Ingredient Quantities Each ingredient is a string in the exact format `"<quantity> <unit> <name>"`. Multiply every quantity by `servings` and return the scaled strings in the original order. ### Function Signature ```python def scale_ingredients(ingredients: list[str], servings: int) -> list[str]: ... ``` ### Example ```text Input: ingredients = ["100 g flour", "50 g water", "10 g sugar"] servings = 8 Output: ["800 g flour", "400 g water", "80 g sugar"] ``` ### Constraints - `0 <= len(ingredients) <= 100_000` - `0 <= servings <= 10^9` - Each quantity is a nonnegative integer no greater than `10^9`. - `unit` is one nonempty token; `name` is nonempty and may contain spaces. - Fields are separated by single spaces with no leading or trailing spaces. ### Clarifications - The input quantities describe one serving; scale directly by the supplied serving count. - Preserve the unit, ingredient name, and input order exactly. - For `servings == 0`, every returned quantity is `0`. - Return a new list and do not mutate `ingredients`. ### Hints - Split only enough times to isolate the first two fields from the remaining name.

Quick Answer: Scale ingredient strings by multiplying each leading integer quantity by a serving count while preserving unit, multiword name, and input order. Split only enough fields to isolate the quantity and unit, return a new list, and handle zero servings exactly.

Each ingredient string has quantity, unit, and name fields separated by single spaces. Multiply the integer quantity by servings and return newly formatted strings in the original order while preserving each unit and full ingredient name.

Constraints

  • servings is a nonnegative integer.
  • Every quantity is a nonnegative integer.
  • The unit is one nonempty token.
  • The name is nonempty and may contain spaces.
  • Do not mutate or reorder the input.

Examples

Input: ([], 4)

Expected Output: []

Explanation: An empty ingredient list remains empty.

Input: (["100 g flour", "50 g water", "10 g sugar"], 8)

Expected Output: ["800 g flour", "400 g water", "80 g sugar"]

Explanation: The prompt quantities scale by eight.

Hints

  1. Split each string at most twice.
  2. Convert only the first field to an integer.
  3. Preserve the second field and entire remaining suffix exactly.
Last updated: Jul 15, 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

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

  • Remove Duplicate Integers While Preserving Order - Upstart (easy)
  • Rewrite Sentence-Ending Punctuation - Upstart (easy)
  • Compute a Point Set's Bounding Rectangle - Upstart (easy)
  • Report Where a Value Appears - Upstart (easy)
  • Interleave Three Equal-Length Strings - Upstart (easy)