using System.Collections.Generic;
internal class TaskSolver
public static void Main(string[] args)
Console.WriteLine("All Test completed!");
public static List<int> GetWordSubWords(List<string> words, List<string> wordDictionary)
List<int> answers = new List<int>();
for (int i = 0; i < words.Count; i++)
for (int j = 0; j < wordDictionary.Count; j++)
var currentWord = words[i];
foreach (char c in wordDictionary[j])
if (currentWord.IndexOf(c) < 0)
currentWord = currentWord.Remove(currentWord.IndexOf(c),1);
public static int FindPath(int[][] gridMap, int sX, int sY, int eX, int eY, int energyAmount)
int mapWidth = gridMap.Length;
int mapHeight = gridMap[0].Length;
int[,] wayMap = new int[mapHeight, mapWidth];
for (x = 0; x < mapHeight; x++)
for (y = 0; y < mapWidth; y++)
wayMap[mapHeight - 1 - x, y] = -2;
wayMap[mapHeight - 1 - x, y] = -1;
if (step > mapWidth * mapHeight)
for (x = 0; x < mapHeight; x++)
for (y = 0; y < mapWidth; y++)
if (wayMap[x, y] == step)
if (x + 1 < mapHeight && wayMap[x + 1, y] == -1)
wayMap[x + 1, y] = step + 1;
if (y + 1 < mapWidth && wayMap[x, y + 1] == -1)
wayMap[x, y + 1] = step + 1;
if (x - 1 > 0 && wayMap[x - 1, y] == -1)
wayMap[x - 1, y] = step + 1;
if (y - 1 > 0 && wayMap[x, y - 1] == -1)
wayMap[x, y - 1] = step + 1;
if (find && wayMap[eX,eY] <= energyAmount)
public static string FormatPrettyCoins(long value, char separator)
var digitsReplace = false;
string valueStr = value.ToString();
if (valueStr.Length >= 6 && valueStr.Length < 8)
valueStr = valueStr.Substring(0, valueStr.Length - 3) + 'K';
else if (valueStr.Length >=8)
valueStr = valueStr.Substring(0, valueStr.Length - 6) + 'M';
if (valueStr.Length >= 4 && !digitsReplace)
valueStr = valueStr.Insert(valueStr.Length - 3, separator.ToString());
else if (valueStr.Length >= 4 && digitsReplace)
valueStr = valueStr.Insert(valueStr.Length - 4, separator.ToString());
public static int FindMaxRect(List<int> heights)
foreach (var currentHeight in heights)
for (int i = 0; i < heights.Count; i++)
if (heights[i] >= currentHeight)
if (currentSequence > maxSequence)
maxSequence = currentSequence;
if (currentSequence > maxSequence)
maxSequence = currentSequence;
currentArea = currentHeight * maxSequence;
if (currentArea > maxArea)
private static void TestGetWordSubWords()
var wordsList = new List<string>
"кот", "ток", "око", "мимо", "гром", "ром",
"рог", "морг", "огр", "мор", "порог"
AssertSequenceEqual( GetWordSubWords(new List<string>{"кот"}, wordsList), new []{2} );
AssertSequenceEqual( GetWordSubWords(new List<string>{"мама"}, wordsList), new []{0} );
AssertSequenceEqual( GetWordSubWords(new List<string>{"погром", "гром"}, wordsList), new []{7, 6} );
AssertSequenceEqual(GetWordSubWords(new List<string>{"рогатка", "море", "open my game"}, wordsList), new[] { 4, 2, 0} );
private static void TestFindPath()
new[] {1, 1, 1, 0, 1, 1},
new[] {1, 1, 1, 0, 1, 1},
new[] {1, 1, 1, 0, 0, 0},
new[] {1, 1, 1, 1, 1, 1},
new[] {1, 1, 1, 1, 1, 1},
new[] {1, 1, 1, 1, 1, 1},
AssertEqual(FindPath(gridA, 0,0,2, 2, 5), 4);
AssertEqual(FindPath(gridA, 0,0,5, 5, 30), -1);
AssertEqual(FindPath(gridA, 0,0,0, 5, 3), -1);
AssertEqual(FindPath(gridA, 5, 5, 0, 0, 3), -1);
private static void TestFormatPrettyCoins()
AssertEqual(FormatPrettyCoins(10, ' '), "10");
AssertEqual(FormatPrettyCoins(1233, ' '), "1 233");
AssertEqual(FormatPrettyCoins(1717310, ' '), "1 717K");
AssertEqual(FormatPrettyCoins(7172343310, ' '), "7 172M");
private static void FindMaxRect()
AssertEqual(FindMaxRect(new List<int>{1, 2, 3, 4, 4, 4, 5, 4, 6}), 24);
AssertEqual(FindMaxRect(new List<int>{1, 2, 3, 5, 5, 4, 2, 4, 6}), 16);
AssertEqual(FindMaxRect(new List<int>{8, 9, 3, 5, 5, 2, 3, 4, 6, 1, 6}), 18);
private static void Assert(bool value)
throw new Exception("Assertion failed");
private static void AssertEqual(object value, object expectedValue)
if (value.Equals(expectedValue))
throw new Exception($"Assertion failed expected = {expectedValue} actual = {value}");
private static void AssertSequenceEqual<T>(IEnumerable<T> value, IEnumerable<T> expectedValue)
if (ReferenceEquals(value, expectedValue))
throw new ArgumentNullException(nameof(value));
if (expectedValue is null)
throw new ArgumentNullException(nameof(expectedValue));
var valueList = value.ToList();
var expectedValueList = expectedValue.ToList();
if (valueList.Count != expectedValueList.Count)
throw new Exception($"Assertion failed expected count = {expectedValueList.Count} actual count = {valueList.Count}");
for (var i = 0; i < valueList.Count; i++)
if (!valueList[i].Equals(expectedValueList[i]))
throw new Exception($"Assertion failed expected value at {i} = {expectedValueList[i]} actual = {valueList[i]}");