Track the energy. The incline is frictionless and the spring is ideal, so the only loss is friction on the rough horizontal stretch.
Distance rubbed. Going in, the block slides d across the rough surface and then a further x while compressing the spring. Coming back it covers the same x and d again: a total path of 2(d+x) on the rough surface.
Energy lost to friction.
Wf=μmg⋅2(d+x).
Spring energy is returned in full, so it cancels between the inward and outward trips.
Energy balance between the two heights.
mgh=mgH−2μmg(d+x)⟹h=H−2μ(d+x).
(The spring constant k and the compression energy 21kx2 do not appear in the final answer: the spring gives back everything it stored: which is why options (C) and (D) are wrong.)
(A)