Denis Jakus

making tech less cryptic

CTO x Unique People

Denis Jakus

making tech less cryptic

CTO x Unique People

CTO Note

19 February 2020 .NET

Today we are going to continue with interview coding tasks.

Task: Depending on input value i.e. (123) create all permutations i.e:(123,213,231,132,312,321)

Solution:

``````
private static void Main(string[] args)
{
WritePermutations();
}``````
``````public static void WritePermutations()
{
var permutations = GetPermutations("123");
foreach (var permutation in permutations)
{
Console.WriteLine(permutation);
}
}``````
``````public static List<string> GetPermutations(string inputString)
{
return IsPermutated(inputString, out var permutations, out var list) ? list : ListOfPermutations(inputString, permutations);
}``````
``````private static bool IsPermutated(string inputString, out List<string> permutations, out List<string> list)
{
permutations = new List<string>();
list = null;
if (inputString == null) return true;
if (inputString.Length != 0) return false;
{
list = permutations;
return true;
}
}``````
``````
private static List<string> ListOfPermutations(string inputString, List<string> permutations)
{
var firstCharacter = inputString[0];
var remainder = inputString.Substring(1);
var words = GetPermutations(remainder);
foreach (var word in words)
{
for (var i = 0; i <= word.Length; i++)
{
}
}
return permutations;
}``````
``````public static string InsertCharacterAt(string word, char character, int i)
{
var start = word.Substring(0, i);
var end = word.Substring(i);
return \$"{start}{character}{end}";
}``````

Cheers

Related Posts
INTERVIEW JOB CODING TASKS – XML file manipulation

Facebook Twitter Evernote Hacker News Gmail Print Friendly Yahoo Mail reddit LinkedIn Blogger Tumblr Like It’s been a while, once…

INTERVIEW JOB CODING TASKS – Calculate Tree depth and a number of leaves

Facebook Twitter Evernote Hacker News Gmail Print Friendly Yahoo Mail reddit LinkedIn Blogger Tumblr Like Season 1 – Prologue So……

• Brianmuh 22:08 24 March 2020

Great looking internet site. Presume you did a lot of your very own html coding.

• Brianmuh 11:19 04 April 2020

Sustain the excellent work and delivering in the crowd!

• Jamesjus 06:20 24 April 2020

Keep up the excellent work and generating the group!

• 파라오카지노 12:35 16 October 2020

Hello There. I found your weblog the use of msn. This is a very smartly
written article. I will make sure to bookmark it and come back to learn more of