Marlabs Interview Question

one sql question and one algorithm