DOJ logoDOJ
Problems
Recently added problemsSaved problemsWorkbooks
CategoriesDLCContestsGroupsTeamsBoard
Ranking
Solved Problem RankingStreak rankingDOJ Power ranking
Status
Call for TasksLoginRegister
DOJ logoDOJ

Community online judge with OI-style subtask scoring, Elo ratings, and Discord account linking.

Problems
ProblemsCategories
Community
ContestsRankingBoardNoticesHost an external contestGuide
Account
LoginRegisterJudge Status
Policy
Terms of ServiceDLC RulesPrivacyAPI documentationLanguage runtimesContest rank rewardsRating and performance
© 2026 DOJ
All rights reserved
Editorial

Sorting Strings

Back to problem

Editorial

Count the 26 letter frequencies and sort by the tuple (score, length, string). The score is at most 202=40020^2=400202=400, and the total input length is at most 10610^6106. Time is O(20Nlog⁡N)O(20N\log N)O(20NlogN). Selection sort suffices for the small subtask.