The pairing mechanism in high critical temperature (T_c) superconductors is one of the outstanding mysteries of condensed matter physics. Here we show that for cuprates and pnictides both electron-phonon interaction (EPI) and electron-electron interaction (EEI) are necessary ingredients. To investigate the role of EPI in the superconducting mechanism we need an experiment that yields a direct measure of the EPI strength. EPI is the dominant mechanism of electron energy relaxation, which we study using femtosecond optical pump-probe spectroscopy. Systematic investigation of different compound families and different doping levels shows that T_c depends universally on two phenomenological parameters: the relative doping level x/x_opt as a measure of EEI, and the lattice-temperature corrected electron-phonon relaxation rate T_l/tau_e-ph as a measure of EPI. This identifies high T_c superconductivity as a collaborative action of EEI and EPI, which puts strong constraints on a possible theory of the pairing mechanism.