rightMax
to store the maximum value to the right of each index.rightMax
by iterating from the end of the nums
array towards the beginning.leftMax
to store the maximum value seen so far from the left.nums
array starting from the second element and ending at the second to last element.nums[j]
, if it is less than leftMax
, calculate the triplet value with rightMax[j + 1]
and update the maximum value if necessary.leftMax
if nums[j - 1]
is greater than the current leftMax
.