Doubt in editorial

why should we need to add idx in arraylist outside the for loop curr.indexes.add(idx);

why this statement curr_xor += (int) Math.pow(2, j); is written in el lse block instead of if block…

else	{																				 
   curr	   =	curr.right;																				 
curr_xor	+=	(int)	Math.pow(2,	j);																 
}