Given three sorted arrays **A[], B[] and C[]**, your task is to write a program that helps to find 3 elements i, j and k from A, B and C respectively such that max(abs(A[i] – B[j]), abs(B[j] – C[k]), abs(C[k] – A[i])) is minimized. Here abs() indicates absolute value.

Example :

```
Input: A[] = {1, 4, 10}
B[] = {2, 15, 20}
C[] = {10, 12}
Output: 5
10 from A, 15 from B and 10 from C
max( abs(10-15) , abs(15-12) , abs(10-10)) that is: 5
Input: A[] = {20, 24, 100}
B[] = {2, 19, 22, 79, 800}
C[] = {10, 12, 23, 24, 119}
Output: 2
```

**Input:**

First line of the input contains an integer **T**, denoting the number of test cases. Then **T** test case follows. First line of each test case contains an integer **'p'** denoting the size of the first array **A[]**. Then next line contains **'p'** space integers denoting the elemets of the array **A[]**. Next line contains an integer **'q'**. Then next line contains **'q'** space sperated integers denoting the elements of the array **B[]**. Next line contains an integer **'r'** denoting the size of array **C[]**. The next line contains **'r'** space separated integers denoting the elements of the array **C[]**.

**Output:**

For each test case Print maximum abs difference of all pairs .

**Constraints:**

1<=T<=100

1<=p,q,r<=10^{3}

**Example:
Input:**

2

3

10 11 12

4

20 21 22 23

5

30 31 32 33 34

5

25 30 35 40 45

5

26 31 36 41 46

5

24 29 34 39 44

18

2

Author: harshitsidhwa

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Vagesh Verma | 98 |

UrGuru | 98 |

chaolinyu | 84 |

prernaus24 | 83 |

devendrachoudhary5485 | 74 |

abducodes | 624 |

harshtyagi36 | 298 |

highway_to_hell | 252 |

rajeswarii | 248 |

arpit_anshuman | 240 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.