XYZ Interview Question

two DSA hard level question