implementation for find_interval