The core insight took me longer than i'd like to admit: if you track where each value sits in the array, then 1..k forms a contiguous block if and only if the spread of those positions (max minus min plus one) equals k.
Track the minimum and maximum positions of values 1..k as you iterate through the permutation. For each k, check if maxPos - minPos + 1 == k; if so, the values form a contiguous subarray. This yields an O(n) solution.
Pro tip: Mention that this works because the values are a permutation of 1..n, so the set {1..k} has exactly k distinct elements. Also, clarify that 'contiguous subarray' means a contiguous segment of the original array, not necessarily starting at index 0.
Confirm that 'contiguous subarray' means a contiguous segment of the original permutation, and that the binary string should have '1' at position k if values 1..k appear together in some order.
Realize that for a set of k distinct integers to occupy a contiguous subarray, the difference between their maximum and minimum positions must be exactly k-1.
Iterate through the permutation, maintaining the minimum and maximum indices seen so far for values 1..k. At each step k, check if maxIndex - minIndex + 1 == k.
Write code to build the binary string, and test with small cases (e.g., n=1, n=3) and edge cases (e.g., already sorted, reverse sorted).
State that the algorithm runs in O(n) time and O(n) space (for storing positions or the result string), which is optimal.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.