Anyscale (CA) interview question

Q: How to implement this function in Python