HITech Quiz - Day 18

HITech Quiz - Day 18

Professional Development

7 Qs

quiz-placeholder

Similar activities

PBO

PBO

Professional Development

10 Qs

PreTrainingWeek3Content

PreTrainingWeek3Content

Professional Development

11 Qs

Sintaxe do Java - Parte 2

Sintaxe do Java - Parte 2

Professional Development

5 Qs

SDA Java Podstawy 1

SDA Java Podstawy 1

Professional Development

6 Qs

Quiz Java cz1

Quiz Java cz1

Professional Development

11 Qs

Quiz String

Quiz String

Professional Development

10 Qs

AppsLab_Q2

AppsLab_Q2

10th Grade - Professional Development

10 Qs

Skill Development - Debugging Practice1

Skill Development - Debugging Practice1

10th Grade - Professional Development

10 Qs

HITech Quiz - Day 18

HITech Quiz - Day 18

Assessment

Quiz

Computers

Professional Development

Medium

Created by

Venkatesh iGen

Used 1+ times

FREE Resource

7 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

10 mins • 1 pt

public class Program {


    public static void main(String[] args) {

        System.out.println(transformPattern("3[x2[y]]")); 

    }


    public static String transformPattern(String input) {

        Stack<String> memory = new Stack<>();


        String temp = "";

        int multiplier = 0;


        for (char ch : input.toCharArray()) {

            if (Character.isDigit(ch)) {

                multiplier = multiplier * 10 + (ch - '0');

            } else if (ch == '[') {

                memory.push(temp);

                memory.push(String.valueOf(multiplier)); // convert integer to string

                temp = "";

                multiplier = 0;

            } else if (ch == ']') {

                int times = Integer.parseInt(memory.pop());

                String previous = memory.pop();

                StringBuilder repeated = new StringBuilder();


                for (int i = 0; i < times; i++) {

                    repeated.append(temp);

                }


                temp = previous + repeated.toString();

            } else {

                temp += ch;

            }

        }


        return temp;

    }

}


xyyxyyxy

xyxyxy

xyyxyyxyy

x2yx2y

2.

MULTIPLE CHOICE QUESTION

10 mins • 1 pt

public class Puzzle {

    public static void main(String[] args) {

        Stack<Integer> bucket = new Stack<>();

        for (int count = 1; count <= 3; count++){

bucket.push(count);

}

        while (!bucket.isEmpty()) {

System.out.print(bucket.pop() + " ");

}

 }

}

1 2 3

3 2 1

123

321

3.

MULTIPLE CHOICE QUESTION

10 mins • 1 pt

import java.util.*;

public class RouteFixer {

public static void main(String[] args) {

System.out.println(cleanRoute("/x/./y/../../z/"));

}

public static String cleanRoute(String route) {

Stack<String> history = new Stack<>();

for (String chunk : route.split("/")) {

if (chunk.equals("..")) {

if (!history.isEmpty()) {

history.pop();

}

} else if (!chunk.equals("") && !chunk.equals(".")) {

history.push(chunk);

}

}

StringBuilder finalPath = new StringBuilder();

for (String step : history) {

finalPath.append("/").append(step);

}

if (finalPath.length() == 0) {

return "/";

}

return finalPath.toString();

}

}

/x/z

/z

/

/y/z

4.

MULTIPLE CHOICE QUESTION

10 mins • 1 pt

public class ExpressionScorer {

    public static void main(String[] args) {

        System.out.println(evaluateBrackets("(()(()))"));

    }


    public static int evaluateBrackets(String expr) {

        Stack<Integer> memory = new Stack<>();

        int points = 0;

        for (char ch : expr.toCharArray()) {

            if (ch == '(') {

                memory.push(points);

                points = 0;

            } else {

                points = memory.pop() + Math.max(2 * points, 1);

            }

        }

        return points;

    }

}

3

4

5

6

5.

MULTIPLE CHOICE QUESTION

10 mins • 1 pt

public class SequenceVerifier {

    public static void main(String[] args) {

        int[] incoming = {1, 2, 3, 4, 5};

        int[] outgoing = {4, 5, 3, 2, 1};


        System.out.println(checkSequence(incoming, outgoing));

    }


    public static boolean checkSequence(int[] addOrder, int[] removeOrder) {

        Stack<Integer> memory = new Stack<>();

        int tracker = 0;

        for (int num : addOrder) {

            memory.push(num);

            while (!memory.isEmpty() && tracker < removeOrder.length && memory.peek() == removeOrder[tracker]) {

                memory.pop();

                tracker++;

            }

        }

        return tracker == removeOrder.length;

    }

}

FALSE

false

true

TRUE


6.

MULTIPLE CHOICE QUESTION

10 mins • 1 pt

import java.util.*;

public class DigitReducer {

    public static void main(String[] args) {

        System.out.println(minDigit("1432219", 3));

    }


    public static String minDigit(String serial, int chop) {

        Stack<Character> buffer = new Stack<>();

        for (char token : serial.toCharArray()) {

            while (!buffer.isEmpty() && chop > 0 && buffer.peek() > token) {

                buffer.pop();

                chop--;

            }

            buffer.push(token);

        }


        while (chop > 0) {

            buffer.pop();

        chop--;

        }


        StringBuilder refined = new StringBuilder();

        for (char elem : buffer) {

            refined.append(elem);

        }


        while (refined.length() > 1 && refined.charAt(0) == '0') {

            refined.deleteCharAt(0);

        }


        if(refined.length() == 0){

            return "0";

        } 

        return refined.toString();

    }

}

1218

1217

1219

1329

7.

MULTIPLE CHOICE QUESTION

10 mins • 1 pt

public class BraceChecker {

    public static void main(String[] args) {

        System.out.println(validSpan(")()())"));

    }

    public static int validSpan(String expr) {

        Stack<Integer> anchor = new Stack<>();

        anchor.push(-1);

        int maxSpan = 0;

        for (int idx = 0; idx < expr.length(); idx++) {

            if (expr.charAt(idx) == '(') {

                anchor.push(idx);

            } else {

                anchor.pop();

                if (anchor.isEmpty()) {

                    anchor.push(idx);

                } else {

                    maxSpan = Math.max(maxSpan, idx - anchor.peek());

                }

            }

        }

        return maxSpan;

    }

}

2

3

4

6