Kattis Challenge "Parking"

Published: September 15, 2017 | Last Modified: May 2, 2025

Tags: kattis coding challenge

Categories: Java

Problem

My solution

import java.util.Scanner;
public class Parking {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for (int i = 0; i < t; i++) {
            int n = sc.nextInt();
            int high = 0;
            int low = 100;
            int d = 0;
            for (int j = 0; j < n; j++) {
                int s = sc.nextInt();
                if (s > high) {
                    high = s;
                }
                if (s < low) {
                    low = s;
                }
                d = (high - low) * 2;
            }
            System.out.println(d);
        }
    }
}