added min distance solution