FastPrepReversible Run-Length Encoding
Problems/Reversible Run-Length Encoding

Reversible Run-Length Encoding

Zillow logoZillow● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report requires reversible compression for digits and special characters but leaves the encoding format open. The judged length-and-code format matches that core task at about 80%.

You are given a list of rows, operations. Each row is either ["ENCODE", text] or ["DECODE", text]. Return one string per row, in the same order.

ENCODE compresses plain text. Split the text into runs: a run is a longest block of the same character in a row. Write each run as count#code;, where count is the length of the run and code is the character's ASCII code, both in decimal. Join the records with nothing in between. For example, "aa1" becomes "2#97;1#49;". The empty string encodes to the empty string.

DECODE does the reverse: it turns a string made by ENCODE back into the original text.

Function

transformRuns(operations: String[][]) → String[]

Examples

Example 1

operations = [["ENCODE","aa11!!"],["DECODE","2#97;2#49;2#33;"],["ENCODE","A;#"]]return = ["2#97;2#49;2#33;","aa11!!","1#65;1#59;1#35;"]

"aa11!!" has three runs: two a (code 97), two 1 (code 49) and two ! (code 33), so it encodes to "2#97;2#49;2#33;". The second row decodes that string back to "aa11!!". In "A;#" every character is its own run: A is 65, ; is 59 and # is 35. Because digits, # and ; are written as codes, decoding never confuses them with the format.

Example 2

operations = [["ENCODE",""],["DECODE",""],["ENCODE","$$$$"]]return = ["","","4#36;"]

The empty string encodes and decodes to the empty string. "$$$$" is one run of four $ characters, and $ has code 36, so it encodes to "4#36;".

Constraints

  • 1 ≤ operations.length ≤ 100000
  • Each row has exactly 2 strings, and the first one is "ENCODE" or "DECODE".
  • The text of an ENCODE row has at most 100000 characters, each a printable ASCII character (codes 32 to 126).
  • The text of every DECODE row is exactly what ENCODE would produce for some valid text.
  • All decoded texts in one call have at most 1000000 characters in total.

More Zillow Phone Screen questions

  • Valid ParenthesesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025
  • Time Based Key-Value StorePHONE SCREEN · Seen Feb 2024
  • Filter Formatted Records by CriteriaPHONE SCREEN · Seen Sep 2023
  • Build a Hash TablePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2023
  • Jump GamePHONE SCREEN · Seen Dec 2022
  • Spiral MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2022
  • Two Sum: All PairsPHONE SCREEN · Seen Nov 2022
  • Employee Free TimePHONE SCREEN · Seen Oct 2022
  • First Unique Character in a StringPHONE SCREEN · Seen Oct 2022
  • K-th Smallest Number in a StreamPHONE SCREEN · Seen Oct 2022

Similar questions at other companies

  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Validate Typed CSV RecordsStripe · PHONE SCREENStripe interview questions
  • Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
  • Format CSV Rows as an ASCII TableAmazon · PHONE SCREEN
  • Correct Apartment Bedroom CountsRamp · OARamp interview questions
  • Parse Command-Line TokensSamsara · ONSITE INTERVIEWSamsara interview questions
  • Rank Word-Translation Hints from Sentence TranslationsDuolingo · PHONE SCREEN · ONSITE INTERVIEWDuolingo interview questions
  • Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Load/Store Arithmetic InterpreterJane Street · PHONE SCREENJane Street interview questions
  • CSV Row SerializerMercor · PHONE SCREENMercor interview questions
All Zillow interview questionsSee Zillow hiring insights
Saved
class Solution {
    public String[] transformRuns(String[][] operations) {
        // Write your code here.
    }
}
Checking account…