Step 1 : Find the largest prefix subarray of the form 3 ^ k + 1
while pow ( 3 , k ) + 1 <= lenRemaining : NEW_LINE INDENT k += 1 NEW_LINE DEDENT lenFirst = pow ( 3 , k - 1 ) + 1 NEW_LINE lenRemaining -= lenFirst NEW_LINE