Solution set

For your review
Time exceeds 100ms in some cases