FastPrepRun-Length Encode a String
Problems/Run-Length Encode a String

Run-Length Encode a String

Google logoGoogle● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This was a PhD intern interview. This problem is rebuilt. The report only keeps that an unusually easy string-processing warm-up was asked. The run-length encoding task is our own rebuild. Our version is about 15% the same as the reported question.

Given a string s, replace every maximal run of equal consecutive characters with the character followed by the run's decimal length.

Concatenate the encoded runs in their original order and return the resulting string. Return an empty string when s is empty.

Function

runLengthEncode(s: String) → String

Examples

Example 1

s = "aaabbc"return = "a3b2c1"

The maximal runs are aaa, bb, and c, with lengths 3, 2, and 1.

Example 2

s = "abcd"return = "a1b1c1d1"

Every character forms a run of length one.

Example 3

s = ""return = ""

There are no runs to encode.

Constraints

  • 0 <= s.length <= 200000
  • s contains lowercase English letters.

More Google Phone Screen questions

  • Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
  • Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Logger Rate Limiter with Every-Arrival HistoryPHONE SCREEN · Seen Nov 2026
  • Minimum Total Layover WaitPHONE SCREEN · Seen Nov 2026
  • Reach a Destination Through Scheduled FlightsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Search and Format ContactsAdyen · PHONE SCREENAdyen interview questions
  • Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
  • Portfolio Valuation, Part 1Stripe · PHONE SCREENStripe interview questions
  • Format a Signed Integer with CommasHudson River Trading · PHONE SCREENHudson River Trading interview questions
  • Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions
  • Run-Length DecodingApple · PHONE SCREENApple interview questions
  • Trace Pointer Rebinding and Pointee UpdatesArista Networks · PHONE SCREENArista Networks interview questions
  • Match a Variadic Function SignatureConfluent · PHONE SCREENConfluent interview questions
  • Decode and Store StringsAirbnb · PHONE SCREENAirbnb interview questions
  • Delimiter-Parsing String Iteratoramo · PHONE SCREEN

Interview reports that mention this question

  • Google SWE Intern Onsite Questions: 16 Experiences (Part 2 of 3)

Google interview experiences

  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
  • Google AI Coding Interview and AI OA: 2 Experiences
  • Google SWE Intern Interview Results Timeline: 13 Experiences
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public String runLengthEncode(String s) {
        // Write your code here.
    }
}
Checking account…