Anatta interview question

Write an algo to Coding pattern