Jenius Bank interview question

Math style leetcode question, leetcode medium / hard