Marlabs interview question

one sql question and one algorithm