Adding maxinterval in both C++ and Java