BackmediumStrings Infosys Salesforce

Decoding Recipe Ingredients Solution

Problem Statement

Given a string of ingredients where each ingredient is followed by its quantity, write a function to reconstruct the original recipe from the given string.

Example 1
Input
A2B3D1E4
Output
AAABBBDEEEEEE

Explanation: Step-by-step: 1. Split the input string into ingredients and quantities. 2. Initialize an empty string to store the result. 3. Iterate over the ingredients and quantities. For each ingredient, append it to the result string the specified number of times. 4. Return the final result string.

Example 2
Input
C2D1E3
Output
CCDDEEE

Explanation: Step-by-step: 1. Split the input string into ingredients and quantities. 2. Initialize an empty string to store the result. 3. Iterate over the ingredients and quantities. For each ingredient, append it to the result string the specified number of times. 4. Return the final result string.

Constraints

  • 1 <= length of input string <= 100
  • Ingredient quantities are between 1 and 9
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free