← All problemsSign in

Decompression

You are given a character string S of length N (1-indexed) and an array x of N integers. Now, you want to form a new string R as follows. For each position i in the array x, you pick an integer k uniformly randomly from range 1 to x[i] and repeat the character S[i], k times in R. You have to find the expected (average) length of decompressed string. Input First line of the input contains an int

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