Run-Length Encoding
Updated
Problem statement
Encode every maximal run of equal consecutive characters in s as the character followed by the decimal run length. Include the count even when it is 1. Runs separated by a different character stay separate.
Character comparison is case-sensitive. Return an empty string for an empty input.
Function
runLengthEncode(s: String) → StringExamples
Example 1
s = "aaaabbbccdaa"return = "a4b3c2d1a2"The runs are aaaa, bbb, cc, d, aa, with lengths 4,3,2,1,2.
Example 2
s = "aA"return = "a1A1"The two letters differ in case and form separate runs.
Constraints
0 <= s.length <= 20000.scontains only uppercase or lowercase English letters.
More Expedia Online Assessment questions
- Balanced NumbersOA · Seen Aug 2026
- REST API: Discounted PriceOA · Seen Aug 2026
- Maximum Team SizeOA · Seen Mar 2026
- Per-Domain Request LimiterOA · Seen Oct 2025
- Count Equal-Frequency SubsequencesOA · Seen Mar 2025
- Count Increasing Stock PeriodsOA · Seen Mar 2025
- Get Minimum StepsOA · Seen Oct 2024
- Rank Songs by PopularityOA · Seen Oct 2024
- Calculate the SumOA · Seen Oct 2024
- Get Maximum EfficiencyOA · Seen Oct 2024
Similar questions at other companies
- Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
- Branch with the Most FilesCapital One · OACapital One interview questions
- REST API: Highest International StudentsRippling · OARippling interview questions
- Rearrange String by Alternating EndsHudson River Trading · OAHudson River Trading interview questions
- Filter Isolated Interior Signal BitsSEDEMAC · OA
- Scale Ingredient QuantitiesUpstart · OAUpstart interview questions
- Telephone Keypad String EncodingEpic · OAEpic interview questions
- Count Invalid Log GroupsIBM · OAIBM interview questions
- Count Case-Insensitive TripletsTikTok · OATikTok interview questions
- Simulate a Deterministic Finite AutomatonPoint72 · OAPoint72 interview questions