Netskope Interview Question

Problem from leet code blind 75