At first, I imagine what the most obvious solution might be. I code it. Then I try to optimize it in a second attempt. Then I compare both with a benchmark.
Note that my "most efficient" solutions usually aren't the same as the ones you unlock after submitting a correct answer. (Of course, my solutions aren't optimal.)