Т-Банк · июль 2024

Тех собес на middle-senior Java Разработчик в Т-Банк

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

Этап 1: Код-ревью (Java Spring)

1. Задача: Провести ревью кода сервиса тарификации вознаграждений

@Service
public class RewardBillingService {
    @Autowired
    private RewardRepository rewardRepository;

    @Autowired
    private TariffRepository tariffRepository;

    @Autowired
    private RewardRestClient rewardRestClient;

    @Transactional
    public void handleRewards(List<Employee> employees) {
        for (Employee employee : employees) {
            List<Reward> rewards = rewardRepository.findByEmployeeId(employee.getId());
            for (Reward reward : rewards) {
                if (List.of("speech", "lesson", "help").contains(reward.getType())) {
                    Tariff tariff = tariffRepository.findByTypeAndDate(reward.getType(), new Date()).get();
                    double amount = (1 + employee.getBonusCoefficient()) * tariff.getAmount();
                    rewardRestClient.payReward(employee.getId(), amount);
                    System.out.println("Отправлен платеж");
                }
            }
            reward.setStatus("paid");
            rewardRepository.save(reward);
        }
    }
}
2

Этап 2: SQL запрос

Условие

CREATE TABLE profile (
    id BIGSERIAL PRIMARY KEY,
    nickname VARCHAR,
    registered_at TIMESTAMP
);

CREATE TABLE post (
    id BIGSERIAL PRIMARY KEY,
    owner_id BIGINT REFERENCES profile (id),
    body TEXT,
    inserted_at TIMESTAMP,
    likes_count INT
);

CREATE TABLE subscription_count (
    profile_id BIGINT REFERENCES profile (id) UNIQUE,
    followers_count INT,
    following_count INT
);

2. Задача: Выбрать профили, у которых больше 10 постов

3

Этап 3: Задача по строкам (Java)

Практика

3. Задача: Объяснить вывод кода при сравнении строк

String a = "123";
String b = "123";
String c = new String("123");

System.out.println(a == b);
System.out.println(a == c);
System.out.println(a.equals(b));
System.out.println(a.equals(c));
4

Этап 4: Задача по многопоточности (Java)

Практика

4. Задача: Проанализировать код, выявить проблему и предсказать вывод

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
 
public class Increment {
    private static int counter1 = 0;
    private static int counter2 = 0;
 
    public static void main(String[] args) throws InterruptedException {
        int tasksCount = 100_000;
        CountDownLatch latch = new CountDownLatch(tasksCount);
        ExecutorService executor = Executors.newFixedThreadPool(10);
 
        for (int i = 0; i < tasksCount; i++) {
            executor.submit(() -> {
                counter1++;
                counter2++;
                latch.countDown();
            });
        }
 
        latch.await();
        executor.shutdown();
 
        System.out.println(counter1);
        System.out.println(counter2);
        System.exit(0);
    }
}
5

Вложения