private int countVerticalInstructions(String instructions) {
        int verticalInstructions = 0;
        for (char c : instructions.toCharArray()) {
            if (c == 'U' || c == 'D') {
                verticalInstructions++;
            }
        }
        return verticalInstructions;
    }