IBM Interview Question

Coding question in hacker rank platform