Loading...

Testdome Java Questions And Answers May 2026

public LocalDateTime getAlert(UUID id) return alerts.get(id);

TreeSet automatically sorts elements naturally (alphabetically). The explicit null checks prevent NullPointerException on hidden test #4. 2. The "Train Composition" Problem (Deque & Performance) Prompt: A TrainComposition is built by attaching and detaching wagons from the left and right sides. Implement attachWagonFromLeft , attachWagonFromRight , detachWagonFromLeft , and detachWagonFromRight .

public UUID addAlert(LocalDateTime time) UUID id = UUID.randomUUID(); alerts.put(id, time); return id; testdome java questions and answers

Set<String> set = new TreeSet<>(); // TreeSet maintains sort order if (arr1 != null) for (String s : arr1) if (s != null) set.add(s); // Some tests inject null strings if (arr2 != null) for (String s : arr2) if (s != null) set.add(s); return set.toArray(new String[0]);

class MapAlertDAO private Map<String, LocalDateTime> alerts = new HashMap<>(); // ... public LocalDateTime getAlert(UUID id) return alerts

This separates juniors from intermediates. The traps: floating-point precision, division by zero, and the order of outputs. public class QuadraticEquation public static double[] findRoots(double a, double b, double c) if (a == 0) // Linear case bx + c = 0 if (b == 0) return null; double root = -c / b; return new double[]root; double discriminant = b * b - 4 * a * c; if (discriminant < 0) return null; if (Math.abs(discriminant) < 1e-10) // Handle near-zero as zero double root = -b / (2 * a); return new double[]root; double sqrtD = Math.sqrt(discriminant); double root1 = (-b - sqrtD) / (2 * a); double root2 = (-b + sqrtD) / (2 * a); // Return sorted ascending if (root1 < root2) return new double[]root1, root2; else return new double[]root2, root1;

This tests your knowledge of Deque (double-ended queue). Using an ArrayList here fails the performance test for 1 million operations. import java.util.ArrayDeque; import java.util.Deque; public class TrainComposition private Deque<Integer> deque = new ArrayDeque<>(); This separates juniors from intermediates

// Returns true if string is palindrome, ignoring case and non-alphanumeric public static boolean isPalindrome(String s) // Write solution using two pointers