Anyone can help to optimise it or have better approach?
Can you share question link?
I think O(n) is fine but you may try for binary search on index. Like if you know first term and d of AP then you can know index of each element.
I would suggest finding the sum of n terms of an AP in O(1) and subtracting from array sum as done below-
int sumOfAP=(num_of_terms / 2) * (2 * first_Term + (n) * d);
This is best approach.