Read the specification
Identify parameters, return type and supplied helper methods. Do not treat your assumptions as requirements. Summarise the task in one sentence.
Check the solution
Choose one ordinary input and one boundary case. Trace loop limits and the return statement. Distinguish array length from String length() and ArrayList size().
Learn from feedback
Compare your code with official scoring criteria. Identify missing behaviour and rewrite the idea using different data. Do more than read a finished solution.