1562. Find Latest Group of Size M
https://leetcode.com/problems/find-latest-group-of-size-m
Description
Given an array arr
that represents a permutation of numbers from 1
to n
. You have a binary string of size n
that initially has all its bits set to zero.
At each step i
(assuming both the binary string and arr
are 1-indexed) from 1
to n
, the bit at position arr[i]
is set to 1
. You are given an integer m
and you need to find the latest step at which there exists a group of ones of length m
. A group of ones is a contiguous substring of 1s such that it cannot be extended in either direction.
Return the latest step at which there exists a group of ones of length exactly m
. If no such group exists, return -1
.
Example 1:
Example 2:
Example 3:
Example 4:
Constraints:
n == arr.length
1 <= n <= 10^5
1 <= arr[i] <= n
All integers in
arr
are distinct.1 <= m <= arr.length
ac
Last updated