Find total minutes without the overlapping times

I think I have a lag/lead implementation that gives your desired results, does the following work for you?

with t as (
  select starttime,
    case when Lag(endtime) over (order by starttime) > starttime then 0 else 1 end UseStart,
    case when endtime < Lead(starttime) over(order by starttime) 
        then endtime 
      else Lead(endtime,1,endtime) over (order by starttime) 
    end endtime
 from tim
)
select starttime, endtime, DateDiff(minute,starttime, endtime) Diff 
from t
where UseStart=1

Working fiddle