FastPrepRun-Length Encoding
Problems/Run-Length Encoding

Run-Length Encoding

Zscaler logoZscaler● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names Run Length Encoding and requires a C implementation. It leaves out how a single character is written, a portable interface, the character set, the empty case, and the limits. Our version is about 58% the same as the reported question.

Given a string text, encode each maximal run of equal consecutive characters from left to right.

For every run, append the run's character followed by the full run length in base 10. Include the count 1 for a singleton run.

Return the concatenated encoding. Return an empty string when text is empty.

Function

runLengthEncode(text: String) → String

Examples

Example 1

text = "aaabbccccd"return = "a3b2c4d1"

The runs are aaa, bb, cccc, and d. Every run contributes its count.

Example 2

text = ""return = ""

An empty input has no runs.

Example 3

text = "zzzzzzzzzzzzx"return = "z12x1"

The first run shows a multi-digit count, and the singleton x still contributes 1.

Constraints

  • 0 <= text.length <= 200000
  • text contains printable ASCII characters.

More Zscaler interview questions

  • Asteroid CollisionONSITE INTERVIEW · Seen Sep 2024
  • Check Whether a Byte Is NonzeroONSITE INTERVIEW · Seen Sep 2024
  • Count Vowel PermutationsONSITE INTERVIEW · Seen Sep 2024
  • Longest Common Subsequence LengthONSITE INTERVIEW · Seen Jun 2024
  • Rate Limiter with Hourly and Daily Effort QuotasPHONE SCREEN · Seen Jul 2026
  • Merging PalindromesPHONE SCREEN · Seen Sep 2024
  • Find the Element With Odd FrequencyPHONE SCREEN · Seen Jun 2024
  • Merge IntervalsPHONE SCREEN · Seen Jun 2024
  • Sum of Divisors of the Array GCDPHONE SCREEN · Seen Jun 2024
  • How Many Sentences? 🌿OA · Seen Mar 2024

Similar questions at other companies

  • Longest Spoken PrefixElevenLabs · ONSITE INTERVIEWElevenLabs interview questions
  • Palindrome Check Ignoring SymbolsWalmart · ONSITE INTERVIEWWalmart interview questions
  • Reverse a String Keeping Dashes in PlaceNykaa · ONSITE INTERVIEWNykaa interview questions
  • Reverse Vowels of a StringGoogle · ONSITE INTERVIEWGoogle interview questions
  • Valid Palindrome After NormalizationKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Count Binary SubstringsDocuSign · ONSITE INTERVIEWDocuSign interview questions
  • Minimum Changes for Palindromic BlocksCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
  • Palindrome Match PercentageApple · ONSITE INTERVIEWApple interview questions
  • Reverse A StringNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
  • Validate a Word AbbreviationSalesforce · ONSITE INTERVIEWSalesforce interview questions

Interview reports that mention this question

  • Zscaler Campus Drive Interviews: 4 Experiences (Part 6 of 6)
  • Zscaler Intern, QA and SRE Rounds: 7 Experiences (Part 3 of 6)
  • Zscaler SDE C++ and OS Rounds: 7 Experiences (Part 2 of 6)
  • Zscaler Campus SDE Interviews: 37 Experiences (Part 1 of 6)

Zscaler interview experiences

  • Zscaler Java, QA and Cloud Rounds: 8 Experiences (Part 5 of 6)
  • Zscaler UI and DevTest Rounds: 8 Experiences (Part 4 of 6)
All Zscaler interview questionsSee Zscaler hiring insights
Saved
class Solution {
    public String runLengthEncode(String text) {
      // write your code here
    }
}
Checking account…