employer cover photo
employer logo
employer logo

Palantir Technologies

Is this your company?

Palantir Technologies interview question

Sort a string by the order it's characters appear in another string.

Interview Answer

Anonymous

Sep 3, 2014

Create a map of every unique character in the reference string to the index of its first appearance in the reference string. Using this map, convert working string into array of indices. Numerically sort this array of indices. Using the inverse of the aforementioned map, map the array of indices back into an array of characters. Depending on the language, then join the character array back into a string.

1