We think about this case : input: 10 8 1 2 1 8 3 1 8 9 1 8 2 Output: 14 Explanation:- 2 ( 1 ) 1 ( 2 ) 8 ( 3 ) 3 ( 4 ) 1 ( 5 ) 8 ( 6 ) 9 ( 7 ) 1 ( 8 ) 8 ( 9 ) 6 ( 10 ) When we work on 2 then no pair added When we work on 1 then no pair added When we work on 8 then 2 pair added 1 to 3 2 to 3 When we work on 3 then 2 pair added 1 to 4 2 to 4 When we work on 1 then 3 pair added ...
I am Tanvir Ahmmad from Bangladesh. Working as a competitive programmer. It will be very pleasure to help you. Happy coding...