Rivian Interview Question

1 algorithm question to solve.