Optimal Two-Stage Algorithms for Group Testing Problems