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.

Sulagna | 117 |

RUTVIKHARIPARA | 116 |

janvidavda105190 | 93 |

harshsiddhapura105461 | 93 |

devsinghindra | 80 |

PiyushPandey4 | 614 |

ASWATHAMA | 561 |

akhyasharma01 | 547 |

john_wick | 521 |

jagrit_07 | 443 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.