Find the original coordinates whose Manhattan distances are given | Java implementation of the approach ; Function to find the original coordinated ; Maximum of the given distances ; Sum of the given distances ; Conditions when the solution doesn 't exist ; First coordinate ; Second coordinate ; Third coordinate ; Driver code
import java . io . * ; class GFG { static void solve ( int d1 , int d2 , int d3 ) { int maxx = Math . max ( d1 , Math . max ( d2 , d3 ) ) ; int sum = ( d1 + d2 + d3 ) ; if ( 2 * maxx > sum sum % 2 == 1 ) { System . out . print ( " - 1" ) ; return ; } int x1 = 0 , y1 = 0 ; int x2 = d1 , y2 = 0 ; int x3 = ( d1 + d2 - d3 ) / 2 ; int y3 = ( d2 + d3 - d1 ) / 2 ; System . out . print ( " ( " + x1 + " , ▁ " + y1 + " ) , ▁ ( " + x2 + " , ▁ " + y2 + " ) ▁ and ▁ ( " + x3 + " , ▁ " + y3 + " ) " ) ; } public static void main ( String [ ] args ) { int d1 = 3 , d2 = 4 , d3 = 5 ; solve ( d1 , d2 , d3 ) ; } }