#791

Custom Sort String

medium · 72.3% accepted · 3,822 likes · top 82%

hash table · string · sorting

⊣ practice⊣ open on leetcode ↗

Description

You are given two strings order and s. All the characters of order are unique and were sorted in some custom order previously.

Permute the characters of s so that they match the order that order was sorted. More specifically, if a character x occurs before a character y in order, then x should occur before y in the permuted string.

Return any permutation of s that satisfies this property.

Solution