Bug in problem 791. Custom Sort String

My code returns perfectly valid answer, and was not accepted:

Input:
"ytpdiusowvgljemhfk"
"pwochmlbbduhqtgsgehudbzkniacltviwlyfinwvoidbsmerlfuidqjasezpmgsbzsmdtmenhyygkimeqptmkkbowspgipkwxrjf"

Output:
"yyyttttpppppdddddiiiiiiiuuussssssooowwwwwvvggggglllljjeeeeemmmmmmhmhhhfffkkkkkcbbqbznacnbrqazbznqbxr"

Expected:
"yyyttttpppppdddddiiiiiiiuuussssssooowwwwwvvggggglllljjeeeeemmmmmmmhhhhfffkkkkkaabbbbbbccnnnqqqrrxzzz"

As you can see, "expected" answer has characters [at the end] that are not in "order" string sorted, while my answer preserves the original order. Problem only requires characters that are in "order" string to be sorted, so my answer is correct. Moreover, my code actually makes better choice [to preserve] since order of characters that are not in "order" string is undefined.

My code (C#):

	using System.Collections.Generic;
	using System.Linq;

	public class Solution
	{
		public string CustomSortString(string order, string str)
		{
			var dic = new Dictionary<char, int>();
			for (int i = 0; i < order.Length; i++)
			{
				dic.Add(order[i], i);
			}
			var list = str.Where(x => dic.ContainsKey(x)).ToList();
			list.Sort((x, y) => dic[x] > dic[y] ? 1 : -1);
			return new string(list.Concat(str.Where(x => !dic.ContainsKey(x))).ToArray());
		}
	}
Comments (1)