Sort Product Codes π
Amazon has millions of products sold on its e-commerce website, and each product is identified by its product code.
Given an array of n productCodes and order, a string that represents the precedence of characters, sort the productCodes in lexicographically increasing order per the precedence.
Note: Lexicographical order is defined in the following way. When we compare strings s and t, first we find the leftmost position with differing characters: sl and tl. If there is no such position (i.e. s is a prefix of t or vice versa) the shortest string is less. Otherwise, we compare characters sl and t[i] according to their order in the given precedence order.
Complete the function sortProductCodes in the editor below. sortProductCodes has the following parameter(s):
string order: the new precedence order stringproductCodes[n]: the array to sort
Returns
string[n]: the productCodes array in sorted order
1Example 1
Constraints
Limits and guarantees your solution can rely on.
1 ≤ n ≤ 50001 ≤ length(productCodes[i]) ≤ 100