Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Run-length compression

    Run-length compression

    Easystringtwo pointers

    Write each run of identical letters as the letter followed by its count, or just the letter when the count is 1. For example aaabcc becomes a3bc2.

    Example 1

    Input:  s = "aaabcc"
    Output: "a3bc2"

    Example 2

    Input:  s = "abc"
    Output: "abc"

    Constraints

    • 1 ≤ s.length ≤ 10⁴
    • Lowercase letters

    Submit checks your solution against 9 tests, including hidden ones.

    /**
     * @param {string} s
     * @return {string}
     */
    function compress(s) {
      
    }
    
    Sign in to run
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.