Search Header Logo

HITech Quiz - Day 18

Authored by Venkatesh iGen

Computers

Professional Development

Used 1+ times

HITech Quiz - Day 18
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

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

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?