← All problemsSign in

Largest String

You will be given a number string $S$ ($0 \leq S_i \leq 9$) of length $n$. You are allowed to $swap$ characters at index $i$ and $j$. If you swap character at index $i$ and $j$ then it will cost you $| i - j |$ (i.e distance between two indices) rupees. But you have only $K$ rupees. Find the [lexicographically](https://en.wikipedia.org/wiki/Lexicographic_order) largest string which you can get us

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