Optimal Algorithms for the Inhomogeneous Spiked Wigner Model