Pregunta de entrevista de Ericsson

Asked me to code a question and also a logic based question.