Check if a Binary Tree is a Mirror Image or Symmetric in Java.

Check if a Binary Tree is a Mirror Image or Symmetric in Java.
Check if a Binary Tree is a Mirror Image or Symmetric.. Check if a given binary tree is a symmetric or you can also say check whether tree is a mirror of itself (ie, symmetric around its center) Lets see sample input and output: ...

Find Container with Most Water in Java

Find Container with Most Water in Java
Find Container with Most Water. Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together...

Find Power of a Number using Recursion in Java

Find Power of a Number using Recursion in Java
Find Power of a Number using Recursion in Java. Given two integers base and number, write a function to compute base^number.  Assume that base and number are small and will not cause integer overflow. Lets understand what is the input and the...

Find length of longest substring without repeating characters in Java

Find length of longest substring without repeating characters in Java
Length of the longest substring without repeating characters in Java. Given a string, find the length of the longest unique substring. Lets understand what is the input and the expected output. ...

Maximum consecutive one’s in a binary array

Maximum consecutive one’s in a binary array
Find the maximum consecutive 1's in an array of 0's and 1's. And Find length of the longest consecutive One's in binary representation. Given a binary array, find the maximum number of consecutive 1s in this array or find the maximum consecutive...

Find sum of digits of a number until sum becomes single digit

Find sum of digits of a number until sum becomes single digit
Find sum of digits of a number until sum becomes single digit. Given a non-negative integer, repeatedly add all its digits until the result has only one digit. Lets understand what is the input and the expected output. ...

Hamming distance between two Integers in Java.

Hamming distance between two Integers in Java.
Hamming distance between two Integers in Java. Given two integers, find the hamming distance between them.  Hamming Distance: hamming distance is the count of bits that are different at same position in a binary representation of two...

Check if a binary tree is subtree of another binary tree

Check if a binary tree is subtree of another binary tree
Check if a binary tree is subtree of another binary tree. Given two binary trees, check if the first tree is subtree of the second one.  A tree is called subtree if all the nodes and its child of the subtree(S) is present in Tree(T) in the same...

Find element in a sorted array whose frequency is greater than or equal to n/2.

Find element in a sorted array whose frequency is greater than or equal to n/2.
Find Majority Element in a Sorted Array in Java? OR Find element in a sorted array whose frequency is greater than or equal to n/2. Given a sorted array, find the number in array that appears more than or equal to n/2 times. Condition: there...

Check Majority Element in a Sorted Array in Java.

Check Majority Element in a Sorted Array in Java.
Majority Element in a Sorted Array in Java? Given a sorted array, we need to find if a given x is a majority element. What is Majority element: Number occurring more than half the size of the array is called Majority element. Lets understand with...

Difference between CountDownLatch and CyclicBarrier in Java

Difference between CountDownLatch and CyclicBarrier in Java
Difference between CountDownLatch and CyclicBarrier in Java? Difference 1: In CountDownLatch, main thread which mostly invokes latch.await() waits for other threads to call countDown() and count reaches 0. In CyclicBarrier, threads wait for each...

Difference between Join and CountDownLatch in Java

Difference between Join and CountDownLatch in Java
Difference between Join and CountDownLatch? Difference 1: Thread join method waits for other thread to finish before further executing current thread. If t1.join is called in main thread, then main thread will wait at that point until t1 finishes...

ReentrantLock interview questions in Java

ReentrantLock interview questions in Java
ReentrantLock interview questions in Java Reentrant lock is more feature rich than using synchronized method/block. This post assume you have basic idea about Threads and synchronization in Java, If not I recommend going through below Multithreading...

Delete all occurrences of a given key in a linked list.

Delete all occurrences of a given key in a linked list.
Delete all occurrences of a given key in a linked list. Given a Linked list and key to delete, Remove all the occurrences of a given key in singly linked list. Lets understand what is the input and the expected output. ...

Find K largest elements in array using Min Heap.

Find K largest elements in array using Min Heap.
Find K largest elements in array using Min Heap. Given a unsorted array, Find k largest element in array. Find K largest elements in array using Max Heap Lets understand what is the input and the expected output. ...

Find K largest elements in array using Max Heap

Find K largest elements in array using Max Heap
Find K largest elements in array using Max Heap. Given a unsorted array, Find k largest element in array. Heap Sort Algorithm Lets understand what is the input and the expected output. ...

Quick Sort in Java

Quick Sort in Java
Quick Sort in Java. Given a unsorted array, Sort it using Quick Sort Algorithm. Merge sort linked list java Lets understand what is the input and the expected output. ...

How Comparable and Comparator works internally in Java

How Comparable and Comparator works internally in Java
How Comparable and Comparator works internally in Java  In Java, Comparable and Comparator are used for sorting collection of objects. java.lang.Comparable is used to sort collection of same types(classes) like List<Student>, List<Employee>,...

How substring method creates memory leak in Java

How substring method creates memory leak in Java
How substring() method of String class use to create memory leaks before Java 7? We know memory leak happens when any object is not used by the application and also GC is unable  to reclaim memory blocked by that object, in that situation we...

Java Memory Management Interview Questions

Java Memory Management Interview Questions
Java Memory Management Interview Questions   What is memory leak? In Java, Garbage collector handles memory management, but when garbage collector is not able to free any object that is not used by the application but it still holds the...
Page 1 of 2812345...28Next »