Loading...
Loading...
You are given an integer array perm of length n that contains every integer from 1 to n exactly once.
A subarray is a contiguous block of elements of perm. For a number k from 1 to n, call k complete if some subarray of length k contains exactly the integers from 1 to k, in any order.
Return a string of length n made of the characters '0' and '1'. Its k-th character, counting from 1, is '1' if k is complete and '0' otherwise.
Input: perm = [4,5,1,3,2,6]
Output: "101011"
Explanation: k = 1 is complete because of the subarray [1]. k = 2 is not: 1 sits at index 2 and 2 sits at index 4, so any subarray holding both has length at least 3. k = 3 is complete because of [1,3,2]. k = 4 is not: 4 sits at index 0 and 2 sits at index 4, so any subarray holding both has length at least 5. k = 5 is complete because of [4,5,1,3,2], and k = 6 is the whole array.
Input: perm = [5,3,1,2,4]
Output: "11111"
Explanation: The subarrays [1], [1,2], [3,1,2], [3,1,2,4], and [5,3,1,2,4] make every k complete.
Input: perm = [1]
Output: "1"
Explanation: The only subarray is [1], so k = 1 is complete.
Input: perm = [2,1]
Output: "11"
Explanation: [1] makes k = 1 complete, and [2,1] makes k = 2 complete.
perm.length ≤2⋅105perm contains every integer from 1 to n exactly once