How to approach this Longest Subarray difference problem


Hii guys, I am new User here. I have very less idea about competitive programming. Can anyone tell me that How I approach to solve the “Longest Subarray Difference” problem in java?. Guys, I have seen the solution but didn’t get how he think of solving this by Tree DS .
please help me.