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:
...
Home
»
Archives for March 2019
Find Container with Most Water in Java
in
Algorithm,
Array,
Datastructure,
Interviews
- on 19:59:00
- No comments

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
in
Interviews
- on 14:55:00
- No comments

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
in
Interviews,
Strings
- on 12:28:00
- No comments

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
in
Array,
Interviews
- on 03:24:00
- No comments

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
in
Interviews
- on 23:41:00
- No comments

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.
in
Interviews
- on 19:06:00
- No comments

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
in
Algorithm,
Binary Tree,
Datastructure,
Interviews
- on 16:26:00
- No comments

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.
in
Array,
Interviews
- on 15:11:00
- No comments

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.
in
Array,
Interviews
- on 14:45:00
- No comments

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
in
Interviews,
Java,
Multithreading
- on 15:55:00
- No comments

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
in
Interviews,
Java,
Multithreading
- on 14:27:00
- No comments

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
in
Interviews,
Java,
Multithreading
- on 13:11:00
- No comments

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.
in
Algorithm,
Datastructure,
Interviews,
Linked List
- on 13:10:00
- No comments

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.
in
Algorithm,
Datastructure,
Heap,
Interviews
- on 01:25:00
- No comments

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
in
Datastructure,
Heap,
Interviews
- on 20:15:00
- No comments

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
in
Algorithm,
Datastructure,
Interviews,
Sorting
- on 12:13:00
- No comments

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
in
Interviews,
Java
- on 23:48:00
- No comments

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
in
Interviews,
Strings
- on 18:03:00
- No comments

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
in
Interviews,
Java,
Java8
- on 13:05:00
- No comments

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...