Write a function contains that efficiently checks if a given binary search tree (BST) contains a given value. Each node in the tree is defined by a class Node containing value , left , and right . Java Implementation
: You will write or refactor code to pass specific test cases.
TestDome evaluates candidates through hands-on coding challenges.
public class Merger public static int[] mergeSorted(int[] a, int[] b) int[] result = new int[a.length + b.length]; int i = 0, j = 0, k = 0; while (i < a.length && j < b.length) result[k++] = (a[i] <= b[j]) ? a[i++] : b[j++];
CacheEntry(V value, long ttlMillis) this.value = value; this.expiryTime = System.currentTimeMillis() + ttlMillis; testdome java questions and answers
While traditional loops work perfectly fine, using modern streams ( Arrays.stream(arr).filter(...) ) can save you precious time during the test when filtering or transforming collections.
Pass down dynamic minimum and maximum tracking boundaries ( Integer pointers) via recursion to ensure every single descendant conforms to the BST rule. 3. Collection Management: The Unique Product Filter
public class LCA public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) if (root == null) return null;
TestDome questions are often tricky, and special conditions are hidden in the text. Write a function contains that efficiently checks if
: You can add System.out.println() statements to debug your logic. Remove or comment them out before submitting to ensure they do not impact execution time.
: TestDome often rewards clean code. Use the Stream API for concise filtering and mapping when appropriate.
: These test your knowledge of Java syntax, object-oriented programming (OOP) principles, and the Java Collections Framework.
A standard HashSet handles duplication but destroys the sequence. Using a LinkedHashSet preserves the exact sequence elements were introduced. Pass down dynamic minimum and maximum tracking boundaries
The architecture of TestDome’s Java questions is distinct from standard multiple-choice quizzes found on many educational platforms. Rather than focusing solely on syntax memorization, TestDome typically employs a "fill-in-the-blank" or "fix-the-bug" methodology. Candidates are presented with a snippet of code—a class or a method—that is incomplete or contains a logical error. The task is to modify or complete the code so that it passes a hidden suite of unit tests. This structure is designed to simulate real-world development scenarios where a developer must write code that integrates with an existing codebase and meets specific functional requirements. Consequently, a simple "answer" is not merely a keyword but a functional implementation of logic.
Choosing the right Collection. A Set automatically enforces uniqueness.
Iterative traversal avoids memory overhead. Recursive implementations can trigger a StackOverflowError on exceptionally deep or skewed trees during hidden test runs. 3. String Manipulation & Streams (Modern Java)