As usual, go for the moles.
10.42 grams Ni (1 mole Ni/58.69 grams) = 0.1775 moles Ni
4.38 grams C ( 1 mole C/12.01 grams) = 0.36469 moles C
5.10 grams N (1 mole N/14.01 grams) = 0.36403 mole N
Now, the least mole value represents the whole number 1 and it divides the other numbers to get the whole numbers for the subscripts.
0.36469 mole C/0.1775 mole Ni = 2.05, call it 2
0.36403 mole N/0.1775 mole Ni = 2.05, also called 2
As you gave the species order ( though I am not sure of this )
NiC2N2