
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
Microprocessor 8086 Architecture -Module I

Quiz
•
Professional Development
10 questions
Semana 6 - Estructura Secuencial y Condicional

Quiz
•
Professional Development
6 questions
Desafio Mobile

Quiz
•
9th Grade - Professio...
10 questions
Java Strings

Quiz
•
1st Grade - Professio...
10 questions
php- basics

Quiz
•
Professional Development
9 questions
Java lvl2

Quiz
•
Professional Development
10 questions
TypeScript intro

Quiz
•
Professional Development
10 questions
CCNA TEST 3

Quiz
•
Professional Development
Popular Resources on Wayground
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
10 questions
Nouns, nouns, nouns

Quiz
•
3rd Grade
10 questions
9/11 Experience and Reflections

Interactive video
•
10th - 12th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
11 questions
All about me

Quiz
•
Professional Development
22 questions
Adding Integers

Quiz
•
6th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
9 questions
Tips & Tricks

Lesson
•
6th - 8th Grade
Discover more resources for Computers
11 questions
All about me

Quiz
•
Professional Development
10 questions
How to Email your Teacher

Quiz
•
Professional Development
15 questions
Fun Random Trivia

Quiz
•
Professional Development
22 questions
Anne Bradstreet 1612-1672

Quiz
•
Professional Development
18 questions
Spanish Speaking Countries and Capitals

Quiz
•
KG - Professional Dev...
14 questions
Fall Trivia

Quiz
•
11th Grade - Professi...
15 questions
Disney Characters Quiz

Quiz
•
Professional Development
15 questions
Quiz to Highlight Q types & other great features in Wayground

Quiz
•
Professional Development