SpanIdea interview question

Write a code for a given condition