Datadog Interview Question

Algorithm to sort according to a condition