Tesla Interview Question

given two coderpad questions to solve in 30 min