Pregunta de entrevista de SAP

A short leetcode question with half-hour time limit.