We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

# Beautiful Triplets

# Beautiful Triplets

#### Sort by

recency

#### |

#### 1038 Discussions

#### |

Please Login in order to post a comment

java

Hi

Why [0,2,3] islisted as a bewatiful triplet if 0 is not in the sequence? and

2 - 0 = 2 and 3 - 2 = 1?

Thanks

The problem description has a bug: in the Constraints section it says arr[i] > arr[i-1], but in one of the sample inputs that constraint is not met, because there is an index i for which arr[i] == arr[i-1].

Assuming that the correct constraint is arr[i] >= arr[i-1], the generated C++ code has a bug: the generated function return type is int, but the result can easily overflow 32-bit int: if arr is 3000 zeroes, followed by 3000 ones, followed by 3000 twos, and d is 1, the result is 3000*3000*3000 = 27000000000, which overflows 32-bit int.

Here is my O(n) c++ solution, you can watch the implementation here : https://youtu.be/vLD3N79nLSE

}