**Travel and Solve:**
Let us start solving our problem. We are at index=0 initially as shown in the image below:

We will solve our problem using this example and we are not going to show an array of hashmaps in the diagram. Rather, we will use a table to depict the solution steps.

At index 0, we do not have any AP with minimum 2 elements to be kept at maps[0]. So, let us move to index 1.

Here, arr[1]-arr[0]=2-4=-2. So, we have an AP with common differences -2 and 2 elements are present in it. Also, before this index, there was no AP with common difference=-2. So, in the hashmap maps[1], we will put {-2,1} depicting the common difference -2 and number of APs with this common difference till index 1 equals 1.

So, till here, the process was simple. Now, in this step, you have more chances to understand the procedure. We are now at index=3.

We have 2 variables i and j. The variable i is at the current index that we are at and the variable j will always start from 0 and reach till i-1 so that we can calculate the common difference of APs. Are you confused about this? Don-t worry, let's see what the procedure will be.

So, we are at index 3 i.e. i=3. Also, the variable j is kept at index 0. Now, we calculate arr[i]-arr[j]=3-4=-1 and this is a common difference for the AP. Now, we can-t find any AP with common difference -1 till the 0th index i.e. the jth index. So, there is only one AP with common difference -1 till index 3 and that is what we have kept at maps[3] as shown in the image above.

Note that the AP is also shown in the diagram just for the explanation purpose. In the array of hashmaps, we will store only the common difference vs number of APs of that common difference till the ith index at maps[i].

So, we will now move the variable j forward and it comes to index 1. The difference arr[2]-arr[1]=3-2=1 gives a common difference =1. Since there is no AP with common difference=1 till index 2, we will put 1,1 in maps[3] depicting that corresponding to the common difference 1, there is only 1 AP till index 3.

As the previous cases, the AP is shown with the pink color and it is shown just for the explanation purpose.

So, dear reader, we request you try to fill the hashmap maps[5] yourself using the procedure explained above. You should end up with the hashmap filled as shown below:

Till now, we have not got even one AP that contains a minimum of 3 elements. Let us now move to index 4. As usual, j will start from 0.

So, the common difference will be arr[i]-arr[j]=2-4=-2. There is no AP of common difference -2 till index 0. So, we will put -2,1 in the maps[4] and the AP is 4,2.

Now, j will move to index 1. The common difference here is arr[i]-arr[j]=2-2=0. There is no AP of common difference 0 till index 1.. So, we will put 0,1 in maps[4].

Now comes a very interesting point in this solution. The variable j is at index 2. The common difference is arr[4]-arr[2]=2-3=-1. There is one AP for this common difference already till index 3 i.e. {4,3}. So, adding 5 to this AP will make this of size 3 and it is a valid AP for our answer. So, we will add the number of APs till index 3 i.e. 1 into our answer. Why did we take the value from index 3?

This is because one element added to it makes it of size 3 which is a valid AP. But, the value that we will store at index 4 actually gives us the count of the number of APs with a common difference -1 of size at least 2. So, we want APs of size 3 only. Hence, we have taken the value from index 3 to the answer.

So, what will be the value at maps[4]? There are now 2 APs with a common difference -1. The first is the previous AP in which we have now added the value 2 as well i.e. {4,3,2} and the second one is the AP with jth and ith index values that is {3,2}. This is shown in the diagram given below:

Now, j will move to the next index i.e. index 3.So, the common difference will be arr[i]-arr[j]=2-5=-3. There is no AP with common difference -3 till index 3. So, we will put -3,1 into the maps[4].

So, dear reader. We hope that you understand what we are doing here. So, we are left with the last index. Try to fill this yourself and see if the answer changes or you get the answer=1 only. The completely filled hashmap array is given below:

So, dear reader, we recommend you refer to the solution video () to understand the complete procedure explained above in more depth. Let us now look at one exceptional case that we have to handle for this question.