Java program to implement the above approach
import java . util . * ; import java . lang . * ; class pair { int l , r , index ; pair ( int l , int r , int index ) { this . l = l ; this . r = r ; this . index = index ; } } class GFG {