Balanced Values in a Permutation
Asked at Microsoft· Screen
Reported by the problem's creator, not verified
You work with a permutation of the numbers 1 to n.
Examples
Example 1
Input: n =
5, p =[3,1,2,5,4]Output:
11101Explanation: The values
1,1 2and3 1 2each fill a contiguous block, sok = 1, 2, 3give1. The values1to4sit at positions 1, 2, 0 and 4, spanning 5 cells, sok = 4gives0. Fork = 5the whole array is the block.
Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.