Problem Statement | |||||||||||||
A TriFibonacci sequence begins by defining the first three elements A[0], A[1] and A[2]. The remaining elements are calculated using the following recurrence:A[i] = A[i-1] + A[i-2] + A[i-3] You are given a int[] A which contains exactly one element that is equal to -1, you must replace this element with a positive number in a way that the sequence becomes a TriFibonacci sequence. Return this number. If no such positive number exists, return -1. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | The constraints for the elements of the input int[] A do not necessarily apply for the replacement to the missing element. | ||||||||||||
Constraints | |||||||||||||
| - | A will contain between 4 and 20 elements, inclusive. | ||||||||||||
| - | Each element of A will be -1 or between 1 and 1000000, inclusive. | ||||||||||||
| - | Exactly one element of A will be -1. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
| 4) | |||||||||||||
| |||||||||||||