Can rooting remove all malware, viruses and backdoors? I ask this question because I read somewhere that there was a Chinese smartphone with in-built malware which could not removed even by rooting.

(I searched the article everywhere but couldn't find it. So, no source. Sorry!)

Is there a possibility that any kind of malware or virus, that could harm your device and/or your privacy, will remain even after rooting your device?

EDIT: By rooting, I actually meant rooting and then flashing a custom ROM, i.e, reinstall android. Sorry for the confusion.

Can malware and viruses persist after this?
Even after installing custom ROMs some area on the internal storage is left unchanged and if the malware resides in that area of the internal storage it won't be deleted even after you flash a new ROM but it is a very rare case when a malware goes so deep into the system.
If you want another example for this then try to install a boot logo (i know it isn't a malware) but even after you flash 100s of ROMs it will never change the boot logo of your device and this proves that some code remains unchanged even after flashing new ROMs