PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/C3 AI

Decompress an encoded string

Last updated: Mar 29, 2026

Quick Overview

This question evaluates string parsing and manipulation skills, focusing on handling nested encodings and repetition semantics in serialized formats. Commonly asked in Coding & Algorithms interviews for Data Scientist roles, it tests reasoning about nested structures and robustness of parsing logic, representing a practical application–level problem in the domain of string processing and parsing rather than a purely theoretical exercise.

  • Medium
  • C3 AI
  • Coding & Algorithms
  • Data Scientist

Decompress an encoded string

Company: C3 AI

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Onsite

Given an encoded string, return its decoded (decompressed) form. Use the following encoding rule: - A positive integer \(k\) followed by a bracketed substring means the substring is repeated \(k\) times. - Encodings can be nested. Examples: - Input: `"3[a]2[bc]"` → Output: `"aaabcbc"` - Input: `"3[a2[c]]"` → Output: `"accaccacc"` - Input: `"2[abc]3[cd]ef"` → Output: `"abcabccdcdcdef"` Assume: - The input is valid. - Digits only appear as repeat counts. Return the decoded string.

Quick Answer: This question evaluates string parsing and manipulation skills, focusing on handling nested encodings and repetition semantics in serialized formats. Commonly asked in Coding & Algorithms interviews for Data Scientist roles, it tests reasoning about nested structures and robustness of parsing logic, representing a practical application–level problem in the domain of string processing and parsing rather than a purely theoretical exercise.

Related Interview Questions

  • Find longest substring with at least k repeats - C3 AI (Hard)
C3 AI logo
C3 AI
Jul 25, 2025, 12:00 AM
Data Scientist
Onsite
Coding & Algorithms
2
0

Given an encoded string, return its decoded (decompressed) form.

Use the following encoding rule:

  • A positive integer kkk followed by a bracketed substring means the substring is repeated kkk times.
  • Encodings can be nested.

Examples:

  • Input: "3[a]2[bc]" → Output: "aaabcbc"
  • Input: "3[a2[c]]" → Output: "accaccacc"
  • Input: "2[abc]3[cd]ef" → Output: "abcabccdcdcdef"

Assume:

  • The input is valid.
  • Digits only appear as repeat counts.

Return the decoded string.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More C3 AI•More Data Scientist•C3 AI Data Scientist•C3 AI Coding & Algorithms•Data Scientist Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ 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
  • Compare Platforms
  • Discord Community

Support

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

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.