Step 1 : Find the largest prefix subarray of the form 3 ^ k + 1
while ( Math . pow ( 3 , k ) + 1 <= lenRemaining ) k ++ ; lenFirst = Math . floor ( Math . pow ( 3 , k - 1 ) ) + 1 ; lenRemaining -= lenFirst ;