Why mod 1000000007?


What is the relevance of returning the answer ‘modulo 1000000007’ ?


It’s probably just a little trick to make sure the interviewee read the problem thoroughly


In some programming contests where you’re asked to compute potentially huge sums (e.g. sum an array of a million large numbers), they make you modulo by some number to avoid integer overflow.


This article answers the question very well:


The reason behind this is to make sure that only efficient algorithms work in the problems containing large integers (integer overflow check) within allowed limited time.