Testdome Java Questions And Answers

: Understand the required time and space complexity. For example, a "Sorted Search" on a large list usually requires (Binary Search) rather than (Linear Search).

A user is submitting a text input field in a UI. The system needs to check if the input is a valid number, but the current code handles NullPointerExceptions improperly or fails on special characters. Goal: Fix the bug to properly parse integers.

import java.util.HashMap; import java.util.Map; public class TwoSum public static int[] findTwoSum(int[] list, int target) public static void main(String[] args) int[] indices = findTwoSum(new int[] 3, 1, 5, 7, 5, 9 , 10); if(indices != null) System.out.println(indices[0] + " " + indices[1]); Use code with caution. testdome java questions and answers

public LocalDateTime getAlertTime(UUID id) return storage.getAlert(id);

public class UserManager public static String merge(User u1, User u2) return u1.getName().concat(u2.getName()); : Understand the required time and space complexity

public AlertService(AlertDAO dao) // Dependency injection this.storage = dao;

Implement the uniqueNames method. Given two arrays of strings, return a sorted array containing all unique names. The system needs to check if the input

class Node public int value; public Node left, right; public Node(int value, Node left, Node right) value = this.value; left = this.left; right = this.right; public class BinarySearchTree public static boolean contains(Node root, int value) Node current = root; while (current != null) if (current.value == value) return true; else if (current.value > value) current = current.left; else current = current.right; return false; public static void main(String[] args) Node n1 = new Node(1, null, null); Node n3 = new Node(3, null, null); Node n2 = new Node(2, n1, n3); System.out.println(contains(n2, 3)); // Expected output: true Use code with caution. Code Breakdown & Complexity on average for a balanced tree; in the worst-case skewed tree. Space Complexity: auxiliary space.

CacheEntry(V value, long ttlMillis) this.value = value; this.expiryTime = System.currentTimeMillis() + ttlMillis;