Datadog Interview Question

2 Leetcode style question- medium hard