mediumStringsPattern: Mixed
Ingredient Quantity Parser Solution
Problem Statement
Given a string of comma-separated ingredient-quantity pairs, where each ingredient is followed by its quantity, write a function to parse this input string and return a dictionary mapping each ingredient to its corresponding quantity.
Constraints
- 1 <= length of input string <= 100
- Ingredient quantities are between 1 and 9
Time: O(n) Space: O(n)
The optimal approach involves parsing the input string and using the quantity to repeat the character in the output string. This can be achieved by iterating over the input string, separating characters from their quantities, and using a loop to repeat the character. This approach has a linear time complexity.
Run, Test & Submit Code
Ready to practice this challenge? Launch our interactive compilation environment with compiler validation.
Solve on Interactive WorkspaceTested Solutions
No solution code is currently loaded.
Complete this code in the workspace editor.
