Datadog interview question

2 Leetcode style question- medium hard