Last duplicate element in a sorted array
Basic Accuracy: 60.06% Submissions: 535 Points: 1

Given a sorted array with duplicate elements and we have to find the index of the last duplicate element and return the index of it and also return the duplicate element.

Example 1:

â€‹Input : arr[ ] = {1, 5, 5, 6, 6, 7}
Output : 4 6
Explanation:
Last duplicate element is 6 having index 4.â€‹

Example 2:

Input : arr[ ] = {1, 2, 3, 4, 5}
Output: -1

This is a function problem. The input is already taken care of by the driver code. You only need to complete the function dupLastIndex() that takes an array (arr), sizeOfArray (n), and return the two integers denoting the last index of the duplicate element and that duplicate element respectively, and if no duplicate element occurs return -1. The driver code takes care of the printing.

Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).

Constraints:
1 ≤ N ≤ 105
1 ≤ A[i] ≤ 107

We are replacing the old Disqus forum with the new Discussions section given below.