Gap-based inverse sampling