Miaplaza interview question

algorithms refactoring a simple C# code