Increment the count for the last visited element
var back = A [ A . length - 1 ] ; if ( mp . has ( back ) ) mp . set ( back , mp . get ( back ) + 1 ) else mp . set ( back , 1 ) ; if ( mp . get ( back ) > maxVisited ) { maxVisited = mp . get ( back ) ; }