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

DhruvKulshreshtha | 102 |

Radhaakrishna | 64 |

Mr_Bean | 58 |

Rishabh Jain 32 | 58 |

PRATEEK JAIN 16 | 57 |

Mr_Bean | 783 |

Dhirendra121 | 462 |

kinetic | 360 |

kevinyu102589 | 358 |

Guru_console | 330 |

akhayrutdinov | 4926 |

Ibrahim Nash | 4448 |

Quandray | 4261 |

sanjay05 | 3668 |

GB11 | 2857 |

Login to report an issue on this page.