Custom Sort String

Given an order string and another string, reorder the second string so that characters appear in the same relative order as the order string, with any remaining characters appended at the end. The solution is driven by custom ordering, not by default alphabetic order.

Input Format

order = permutation of distinct lowercase letters, s = lowercase string

Output Format

string reordered by the custom order

Constraints

  • 1 <= order.length <= 26; 1 <= s.length <= 200

Examples

Example 1:

Input:

order = "cba"
s = "abcd"

Output:

cbad

Explanation:

Characters c, b, and a are placed first according to order.

Example 2:

Input:

order = "bcafg"
s = "abcd"

Output:

bcad

Explanation:

Characters not in order are appended at the end.

Loading...
Custom Sort String