โ† Amazon questions

Custom Sorting

Filed under Amazon

Free read 2 of 3

Identify the exact sorting criteria (frequency, custom alphabet order, etc.).

The question

Perform a custom sort on a string based on a given custom order or frequency rules.

Constraints

  • String length up to 10^4
  • Characters consist of ASCII values

Examples

Input
s = "cba", order = "abc"
Output
"abc"
Why
Characters of s are sorted according to the custom order string.

Approach

  1. Identify the exact sorting criteria (frequency, custom alphabet order, etc.).

Tips

  • What they are testing: Tests efficient frequency counting and custom comparator implementation.
  • Common mistake: Inefficient sorting algorithms leading to O(N^2 log N) performance instead of O(N).

Related Amazon questions

Collected from public candidate posts and coding forums. Updated Nov 2026.