Reflecting on my own graduate school experience in physics (though the advice applies to mathematics as well), I initially believed that excelling in undergraduate coursework and securing strong letters of recommendation were the keys to admission. While those factors were sufficient at the time, I now realize I placed too much emphasis on coursework alone.
A far more critical strategy is finding ways to contribute to a professor's research program. Even if your role is limited to writing code, collecting data, or running simulations—without delving into the core research questions—this involvement can significantly boost your application.
Looking back, I lacked the confidence and interpersonal skills to pursue such opportunities, but I wish I had pushed myself. My advice to current undergraduates: actively seek out ways to assist in research, even in a supportive capacity. It can make all the difference.