Not able to solve this question completely

https://practice.geeksforgeeks.org/problems/overlapping-intervals/0
what modifications should I make in the below code??

@rohitkandpal683

  1. sort your input array in increasing order based first element of pair.
  2. what the purpose of using j loop in line 23
    3)why are you printing you array till (n-1). The final ans might have less ranges