Sberbank Interview Question

sql query for joining 3 tables with duplicates and cte with some interval chaining logic