Solved it awhile ago in C#.
⚠ Warning: Really ugly...
using System; using System.Collections.Generic; using System.Linq; public class Scramblies { public static bool Scramble(string s1, string s2) { Func<string, Dictionary<char, int>> toMap = s => s.GroupBy(c => c) .Select(g => new { g.Key, Count = g.Count() }) .ToDictionary(pair => pair.Key, pair => pair.Count); var map1 = toMap(s1); var map2 = toMap(s2); foreach (KeyValuePair<char, int> p2 in map2) { if (!map1.ContainsKey(p2.Key)) return false; if (map1[p2.Key] < p2.Value) return false; } return true; } }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Solved it awhile ago in C#.
⚠ Warning: Really ugly...