FastPrepRun-Length String Compression
Problems/Run-Length String Compression

Run-Length String Compression

Oracle logoOracle● EasyFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Oracle onsite interview. The report says to encode runs of the same character from left to right, and to leave out the count for a run of one. It does not give the function signature, what to do with empty input, which characters appear, or the input limits. We spell those out below. Our version is about 90% the same as the reported question.

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

  • Append the run's character once.
  • If the run length is greater than 1, append the full length in base 10.
  • If the run length is exactly 1, append no count.

Return the concatenation of all encoded runs. Return the empty string when text is empty.

Function

compressRuns(text: String) → String

Examples

Example 1

text = "aaabbccccd"return = "a3b2c4d"

The maximal runs are aaa, bb, cccc, and d. The singleton contributes only its character.

Example 2

text = ""return = ""

An empty input has no runs and produces an empty encoding.

Example 3

text = "zzzzzzzzzzzzx"return = "z12x"

The first run demonstrates a multi-digit count. The final singleton x has no count.

Constraints

  • 0 <= text.length <= 200000
  • text contains printable ASCII characters.
  • The returned encoding is formed exactly as specified; it does not need to be shorter than the input.

More Oracle Onsite Interview questions

  • Course ScheduleONSITE INTERVIEW · Seen Nov 2026
  • Shortest Subarray with Sum at Least KONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Minimum Meeting RoomsONSITE INTERVIEW · Seen Nov 2026
  • Shortest Window with Required CountsONSITE INTERVIEW · Seen Nov 2026
  • Maximum Subarray Sum with One DeletionONSITE INTERVIEW · Seen Nov 2026
  • Shortest Deletion for Distinct CharactersONSITE INTERVIEW · Seen Nov 2026
  • Count Dropped Rate-Limited RequestsONSITE INTERVIEW · Seen Nov 2026
  • Design Authentication ManagerONSITE INTERVIEW · Seen Oct 2026
  • Maximum Bouquet ValueONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • String CompressionShnoor International · ONSITE INTERVIEW
  • 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

Oracle interview experiences

  • Oracle SWE Onsite Interview Experience: 1 Experience
All Oracle interview questionsSee Oracle hiring insights
Saved
class Solution {
    public String compressRuns(String text) {
      // write your code here
    }
}
Checking account…