Solution:
Total number of triplets without restriction is n x n x n. The number of triplets with all different coordinates is . Therefore, the required number of triplets is ,
Let A be a set of n distinct elements. The number of triplets (x, y, z) of the A elements in which at least two coordinates is equal to
Total number of triplets without restriction is n x n x n. The number of triplets with all different coordinates is . Therefore, the required number of triplets is ,