In Mosiah 27, Alma the Younger is being very wicked. But then, only two chapters later, in Mosiah 29,
And it came to pass that Alma was appointed to be the first chief judge, he being also the high priest, his father having conferred the office upon him, and having given him the charge concerning all the affairs of the church.
Look at the dates. Mosiah 27 takes place
About 100–92 B.C.
And Mosiah 29 happens
About 92–91 B.C.
Only 9 years at the most, and right away at the least! That just tells us how strong his conversion was, for him to suddenly be righteous enough for the responsibilities of Chief Judge and High Priest!