← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
You are given a permutation p of length n.
A number k is called balanced if there exists a contiguous subarray p[l..r] whose elements form a permutation of the numbers 1, 2, ..., k.
For every k from 1 to n, determine whether k is balanced. Return a binary string of length n where the kth character is:
"1" if k is balanced"0" otherwise
A permutation of length n contains every integer from 1 to n exactly once.1, 3, and 4 are balanced, but 2 is not. For example, [1, 3, 2] is a contiguous permutation of 1..3.
For every k from 1 to 5, the values 1..k occupy a contiguous block somewhere in the permutation.
Only 1 and 4 are balanced. The values 1..2 and 1..3 do not fit inside a contiguous block of lengths 2 and 3.