Is there any API to find the farthest nodes between 2 node groups like we have to find the shortest node(hm_measureshortestdistance)?
No, there isn't.
You can estimate simply as show in below picture : D = D_AB - (D_A + D_B)
How can i do the same in script?
Maybe some ideas: