Java implementation of the approach
import java . util . * ; class GFG { static class pair { char first ; int second ; public pair ( char first , int second ) { this . first = first ; this . second = second ; } }