ByteByteGo logo
menuProblems List

Triangle Numbers

Medium

Consider a triangle composed of numbers where the top of the triangle is 1. Each subsequent number in the triangle is equal to the sum of three numbers above it: its top-left number, its top number, and its top-right number. If any of these three numbers don't exist, assume they are equal to 0.

Given a value representing a row of this triangle, return the position of the first even number in this row. Assume that the first number in each row is at position 1.

Example:

Input: n = 4
Output: 3

Constraints:

  • n will be at least 3.

You can practice coding exercises online by logging into bytebytego.com on your laptop.