Контур · сентябрь 2024

Тех собес на middle-senior C# Разработчик в Контур

middle-senior Тех собес 4 вопроса 3 задачи
1

Задачка с ревью

Практика

1. Задача: Оценить по сложности LINQ-выражение и предложить улучшения

create table table1 (Id int, ParentId int null)
var table = new [] { new { Id = 1, ParentId = null }, new { Id = 2, ParentId = 1 }, new { Id = 3, ParentId = 2 }, new { Id = 4, ParentId = 2 } );
var answer = table.where(x=> x.ParentId != null && !table.Any(y => y.ParentId == x.Id));
table.ToDictionary(c => c.ParentId)

2. Задача: Проанализировать работу IEnumerable и yield return

class Program
{
    static void Main()
    {
        IEnumerable<int> ienum = null;
        try
        {
            ienum = OddSequence(50, 110);
            Console.WriteLine("Retrieved enumerator...");
        }
        catch(Exception ex)
        {
            Console.WriteLine("Catch 1");
            Console.WriteLine(ex);
        }

        try
        {
            foreach (var i in ienum)
            {
                Console.Write($"{i} ");
            }
        }
        catch(Exception ex)
        {
            Console.WriteLine("Catch 2");
            Console.WriteLine(ex);
        }
        Console.ReadLine();
    }

    public static IEnumerable<int> OddSequence(int start, int end)
    {
        if (start < 0 || start > 99)
            throw new ArgumentOutOfRangeException("start must be between 0 and 99.");
        if (end > 100)
            throw new ArgumentOutOfRangeException("end must be less than or equal to 100.");
        if (start > end)
            throw new ArgumentException("start must be less than end.");

        for (int i = start; i <= end; i++)
        {
            if (i % 2 == 1)
                yield return i;
        }
    }
}
2

C# MyStringBuilder

3. Задача: Оценить производительность операций в реализации MyStringBuilder и предложить оптимизации

public class MyStringBuilder
{
    private readonly List<char> chars;

    public MyStringBuilder()
    {
        chars = new List<char>();
    }

    public void AddToEnd(string s)
    {
        chars.AddRange(s);
    }

    public void AddToStart(string s)
    {
        chars.InsertRange(0, s);
    }

    public override string ToString()
    {
        var result = "";
        foreach (var nextChar in chars)
        {
            result += nextChar;
        }
        return result;
    }

    public char this [int index] => chars[index];

    public int GetDifferentCharactersCount()
    {
        var differentCharacters = new List<char>();
        foreach (var c in chars)
        {
            if (differentCharacters.IndexOf(c) == -1)
            {
                differentCharacters.Add(c);
            }
        }
        return differentCharacters.Count();
    }
}
3

Задачка на System Design

Практика

4. Что будет, если какой-то сервис выйдет из строя?

5. Как пользователь узнает на какой стадии находится отчёт?

6. Как избавиться от дубликатов, если пользователь будет спамить кнопку?

7. Как понять, что пользователь отменил запрос и отчёт ему больше не нужен?

Дополнительно

Собеседование включало секцию с ревью кода на C# (LINQ, итераторы, оптимизация структур данных) и секцию по системному дизайну распределённой системы генерации отчётов.

4

Вложения