Help me in solving AIRM problem

Can anyone explain how to approach this problem and the logic to use ?
P.S - I code in C++.

Problem Link:

The logic is count the freq of A[i] and D[i] together and print the max freq
now ex:-
1 1 2
2 2 3
the freq of 1 is 2
the freq of 2 is 3
the freq of 3 is 1
so the max freq is 3 thus it will be our answer.