Balanced Values in a Permutation

Asked at Microsoft· Screen

Reported by the problem's creator, not verified

Import another question

You work with a permutation of the numbers 1 to n.

Examples

  1. Example 1

    Input: n = 5, p = [3,1,2,5,4]

    Output: 11101

    Explanation: The values 1, 1 2 and 3 1 2 each fill a contiguous block, so k = 1, 2, 3 give 1. The values 1 to 4 sit at positions 1, 2, 0 and 4, spanning 5 cells, so k = 4 gives 0. For k = 5 the 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.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.