Blog Archives
1 2 3 4

Find pair of numbers with a given sum in Java

Q. Write a method which takes the parameters (int[ ] inputNumbers, int sum) and checks input to find the pair of integer values which totals to the sum. If found returns true, else returns false? Considerations: Should it work for negative integers? How big is the inputNumbers array? How often… …



Graph from scratch Java example

Q. Java does not have a Graph implementation, how would you go about implementing your own? A. Graphs are data structures that represent arbitrary relationships between members of any data sets that can be represented as networks of nodes and edges. A tree structure is essentially a more organized graph… …



Graph from scratch Java example adjacent matrix approach

Q. Java does not have a Graph implementation, how would you go about implementing your own? A. Graphs are data structures that represent arbitrary relationships between members of any data sets that can be represented as networks of nodes and edges. A tree structure is essentially a more organized graph… …



HashMap from scratch Java example

Q. If Java did not have a HashMap implementation, how would you go about writing your own one? A. Writing a HashMap is not a trivial task. It is also not a good practice to reinvent the wheel. The interviewer is trying to evaluate your level of technical knowledge and… …



Linear & Binary Search in Java

Q. Can you write a code to search for number 5 in 7 3 6 8 2 9 5 4? A. The code below uses the linear search algorithm. The linear search algorithm’s two advantages are simplicity and the ability to search either sorted or unsorted one-dimensional arrays. Its sole… …



LinkedList creating from scratch in Java

Q. How to create a LinkedList from scratch A. Adding Removing Step 1: The node that stores the data and the reference to the next Node.



Queue from scratch Java example

Q. If Java did not have a Queue implementation, how would you go about implementing your own? A. A queue can be implemented in a similar fashion to a stack by declaring a backingArray, a frontIndex, a backIndex, and a currentSize. Initialize the frontIndex to 0 and the backIndex to… …



Quick Sort in Java

Q. Is there a more efficient sorting algorithm than bubble sorting? A. Although bubble-sort is one of the simplest sorting algorithms, it’s also one of the slowest. It has the O(n2) time complexity. Faster algorithms include quick-sort and heap-sort. The Arrays.sort( ) method uses the quick-sort algorithm, which on average… …



Recursion Vs Tail Recursion

Q1. Can you write a sample code that will count the number of “A”s in a given text? Show iterative, recursive, and tail recursive approaches? “AAA rating” A1. Iteration



Single Pointer: Partitioning around a pivotal number

Q. How will you partition the following numbers 7 3 6 8 2 9 5 4 around the pivotal number of 5 so that the lower values are in front of it and higher values are behind it? A. A single pointer can be used by moving from left to… …



1 2 3 4

Java developer & architect Q&As

Java developers Q&As

Top