← All problemsSign in

Add Permutation

CodeChefRating 1406Open on judge ↗

Given a ($1$-indexed) permutation $P$ of the integers in the range $[1, N]$, you will first construct an array $A$ also of size $N$ where $A_i = P_i + i$. Now, let $f(P)$ as the number of **distinct elements** in the array $A$. For example, for $P = [3, 4, 1, 2]$, the constructed array $A$ is $[4, 6, 4, 6]$ and thus $f(P) = 2$. Given integers $N$ and $K$, find a permutation $P$ of the integers

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start