Tap here to switch tabs
Problem
Submissions

Problem: Find Latest Group of Size M

med
30 min
Try to solve the Find Latest Group of Size M problem.

Statement

Given an array arr that represents a permutation of integers from 11 to n, you have a binary string of length n initially containing all 00s.

At each step i (from 11 to n), the bit at position arr[i - 1] (11 based index) is changed to 11.

A group of 11s is defined as a contiguous sequence of 11s such that it cannot be extended to the left or to the right.

Return the latest step at which there exists a group of 11s of length exactly m. If no such group exists at any step, return −1-1.

Constraints:

  • n ==== arr.length

  • 1≤1 \leq m ≤\leq n ≤105\leq 10^5

  • 1≤1 \leq arr[i] ≤\leq n

  • All integers in arr are distinct.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find Latest Group of Size M

med
30 min
Try to solve the Find Latest Group of Size M problem.

Statement

Given an array arr that represents a permutation of integers from 11 to n, you have a binary string of length n initially containing all 00s.

At each step i (from 11 to n), the bit at position arr[i - 1] (11 based index) is changed to 11.

A group of 11s is defined as a contiguous sequence of 11s such that it cannot be extended to the left or to the right.

Return the latest step at which there exists a group of 11s of length exactly m. If no such group exists at any step, return −1-1.

Constraints:

  • n ==== arr.length

  • 1≤1 \leq m ≤\leq n ≤105\leq 10^5

  • 1≤1 \leq arr[i] ≤\leq n

  • All integers in arr are distinct.