F5 Interview Question

Technical question from leet code. 1 medium and 1 hard problem