Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- class Solution {
- public int minMax(int[] X, int[] Y, int[] Z) {
- int difference = Integer.MAX_VALUE;
- int minimum = Integer.MIN_VALUE;
- int maximum = Integer.MAX_VALUE;
- int i = 0, j = 0, k = 0;
- int n = X.length;
- int m = Y.length;
- int o = Z.length;
- while (i < n && j < m && k < o) {
- minimum = Math.min(X[i], Math.min(Y[j], Z[k]));
- maximum = Math.max(X[i], Math.max(Y[j], Z[k]));
- difference = Math.min(difference, maximum - minimum);
- // If difference = 0, then we can return the difference as the minimum value.
- if (difference == 0) {
- break;
- }
- // If the element from the array X is minimum.
- if (X[i] == minimum) {
- i++;
- }
- // If the element from the array Y is minimum.
- else if (Y[j] == minimum) {
- j++;
- }
- // If the element from the array Z is minimum.
- else {
- k++;
- }
- }
- return difference;
- }
- }
- public class Main {
- public static void main(String[] args) throws IOException {
- Scanner sc = new Scanner(System.in);
- int x = sc.nextInt();
- int[] X = new int[x];
- for (int i = 0; i < x; i++) {
- X[i] = sc.nextInt();
- }
- int y = sc.nextInt();
- int[] Y = new int[y];
- for (int i = 0; i < y; i++) {
- Y[i] = sc.nextInt();
- }
- int z = sc.nextInt();
- int[] Z = new int[z];
- for (int i = 0; i < z; i++) {
- Z[i] = sc.nextInt();
- }
- sc.close();
- Solution Obj = new Solution();
- System.out.print(Obj.minMax(X, Y, Z));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement