22 September 2026
Compact Route Codes
Easy
Lists
Strings
Keep the route codes that fit within a chosen length.
A transport board has route codes in display order. You are also given the largest number of characters that fit on a small sign. Look at each code and keep it when its length is at most the limit. Return the kept codes in their original order. If no code fits, return an empty list.
Constraints
codes contains between 0 and 500 ASCII strings.Each code contains between 1 and 20 characters.max_length is between 1 and 20.
Function signature
def compact_route_codes(codes, max_length):