FastPrepTriangle Flags from Adjacent Elements

Triangle Flags from Adjacent Elements

Luma AI logoLuma AI● EasyFULLTIMEOA
Learn

Problem statement

For every three consecutive positive integers in arr, return 1 if they can be the side lengths of a triangle and 0 otherwise.

The result has length arr.length - 2.

Function

adjacentTriangleFlags(arr: int[]) → int[]

Examples

Example 1

arr = [1,2,2,4]return = [1,0]

The triple 1,2,2 is valid, while 2+2 is not greater than 4.

Constraints

  • 3 <= arr.length <= 100000.
  • 1 <= arr[i] <= 10^9.

More Luma AI problems

See Luma AI hiring insights
public int[] adjacentTriangleFlags(int[] arr) {
    // Return one flag for every adjacent triple.
}
arr[1,2,2,4]
expected[1,0]
Checking account…