Count Subsequences

Problem Overview

  • Count subsequences of an integer array whose MEX is in [l, r]; return the count modulo 1e9+7.
  • Input: arr of size n (1≤n≤3e5), with 0≤arr[i]≤1e9; bounds 0≤l≤r≤1e9. Output: number of valid subsequences.
  • Subsequence preserves order; MEX is the smallest missing non‑negative; empty subsequence has MEX 0.
  • Real-world ML data pattern detection context; a coding interview problem and interview question from Bny_mellon interviews.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: