
HITech Quiz - Day 18

Quiz
•
Computers
•
Professional Development
•
Medium
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
Similar Resources on Wayground
10 questions
1. Standard output, Data type and variable

Quiz
•
Professional Development
10 questions
Java main() and Scanner

Quiz
•
Professional Development
11 questions
Quiz Java cz1

Quiz
•
Professional Development
10 questions
Quiz String

Quiz
•
Professional Development
10 questions
AppsLab_Q2

Quiz
•
10th Grade - Professi...
10 questions
PBO

Quiz
•
Professional Development
9 questions
PreTrainingJavaScript

Quiz
•
Professional Development
10 questions
C Programming

Quiz
•
Professional Development
Popular Resources on Wayground
50 questions
Trivia 7/25

Quiz
•
12th Grade
11 questions
Standard Response Protocol

Quiz
•
6th - 8th Grade
11 questions
Negative Exponents

Quiz
•
7th - 8th Grade
12 questions
Exponent Expressions

Quiz
•
6th Grade
4 questions
Exit Ticket 7/29

Quiz
•
8th Grade
20 questions
Subject-Verb Agreement

Quiz
•
9th Grade
20 questions
One Step Equations All Operations

Quiz
•
6th - 7th Grade
18 questions
"A Quilt of a Country"

Quiz
•
9th Grade