We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static List<string> solveLexOrder(List<char> arr)
{
var sorted = arr.OrderBy(c => c).ToList();
return getSubsets(sorted).Select(sb=>sb.ToString()).Cast<string>().ToList();
}
private static List<StringBuilder> getSubsets(List<char> sorted)
{
if (sorted.Count < 1) return new List<StringBuilder>();
var res = new List<StringBuilder> { new StringBuilder(sorted[0].ToString()) };
res.AddRange(getSubsets(sorted.Skip(1).ToList()).Select(sb => new StringBuilder(sorted[0].ToString()).Append(sb)));
res.AddRange(getSubsets(sorted.Skip(1).ToList()));
return res;
}
.......
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Building a List
You are viewing a single comment's thread. Return to all comments →
C# recursive:
.......