Debris under keys can cause intermittent issues. Use compressed air to blow under the affected keys. Wipe keys with a slightly damp microfiber cloth.
Try an external keyboard-If external keyboard works fine, it may be a hardware problem If external keyboard has same issues, then it may be a software/driver problem.
If keys work fine in Safe Mode, a third-party app may be interfering.