Generate all the binary strings of N bits.
Given a positive integer number N. Generate all the binary strings(0 and 1) of N bits.
Case 1 Input: length=2 Output: 0 0 0 1 1 0 1 1
...
Home
»
Archives for 2019
Check if an array is sorted in Java - Iterative and Recursive approach
in
Array,
Interviews,
Java
- on 11:57:00
- No comments

Check if an array is sorted in Java - Iterative and Recursive approach.
Given an array, check if it is already sorted or not using both Iterative and Recursive way.
Lets see sample input and output for better understanding:
Check whether array...
Reverse a Number in Java.
in
Interviews
- on 15:08:00
- No comments

Reverse a Number in Java.
Given a integer number, reverse it.
Lets see sample input and output for better understanding:
Reverse a number in Java input output example...
Find length of the longest valid parenthesis substring
in
Algorithm,
Datastructure,
Interviews,
Stack
- on 18:34:00
- No comments

Find length of the longest balanced parenthesis in a string.
Given a string consisting of opening and closing parenthesis, find the length of the longest balanced parenthesis in it.
Lets see sample input and output for better understanding:
longest...
Sort a Stack using Merge Sort
in
Algorithm,
Datastructure,
Interviews,
Sorting,
Stack
- on 20:38:00
- No comments

Sort a Stack using Merge Sort.
Lets see how to sort a stack using merge sort which uses divide and conquer recursive algorithm.
I recommend reading Merge sort first before proceeding.Also, check Merge sort article on linked list that will help in understanding...
Print path from root to a given node in a binary tree
in
Algorithm,
Binary Tree,
Datastructure,
Interviews
- on 11:05:00
- No comments

Print path from root to a given node in a binary tree.
Given a Binary tree and a Key, Print a path from root to a key node.
Note: Given tree is Binary Tree and not Binary Search Tree.
Lets see sample input and output for better understanding:
Print...
Simple Deadlock Program in Java
in
Interviews,
Java,
Multithreading
- on 19:42:00
- No comments

Simple java program to create Deadlock.
Deadlock describes a situation where two or more threads are blocked forever, waiting for each other.
Let's consider an example, in the office we have shared Printer and Scanner where Employees...
Difference between process and thread
in
Interviews,
Java,
Multithreading
- on 10:25:00
- No comments

Difference between process and thread.
Point 1:
A process is an executing instance of an application.
Thread is independent path of execution within a process. Process can have multiple threads,
Point 2:
Threads itself is capable enough to do...
Delete Middle Node of Linked List in Java
in
Algorithm,
Datastructure,
Interviews,
Linked List
- on 04:13:00
- No comments

Delete Middle Node of Linked List in Java.
Given a linked list, Delete the middle node of linked list.
Lets see sample input and output for better understanding:
...
Remove duplicates from an unsorted linked list in Java.
in
Algorithm,
Datastructure,
Interviews,
Linked List
- on 02:02:00
- No comments

Remove duplicates from an unsorted linked list in Java..
Given an unsorted linked list, Remove duplicates from it.
Lets see sample input and output for better understanding:
...
Check linked list is palindrome or not in java
in
Algorithm,
Datastructure,
Interviews,
Linked List
- on 17:45:00
- No comments

Check linked list is palindrome or not in Java.
A palindromic number is a number that is the same when written forwards or backwards.
Lets see sample input and output for better understanding:
...
Find Running Median from a Stream of Integers
in
Algorithm,
Datastructure,
Heap,
Interviews
- on 03:58:00
- No comments

Find Running Median from a Stream of Integers in Java.
Given that integers are read from a data stream. Find median from the elements read so far in efficient way.
Lets see sample input and output for better understanding:
...
Find Moving Average of Last N numbers in a Stream.
in
Algorithm,
Datastructure,
Interviews
- on 22:34:00
- No comments

Find Moving Average of Last N numbers in a Stream.
You are given a stream of numbers, calculate moving average of last N numbers in a stream.
In other words,
Given a stream of integers and a window size, calculate the moving average of all integers...
Search element In Sorted Rotated Array in Java
in
Array,
Binary Search,
Interviews
- on 02:12:00
- No comments

Search the element In Sorted Rotated Array in Java.
Given an array which is sorted in ascending order and is rotated, say for example
Example: original array [1,2,3,4,5,6,7] might become [3,4,5,6,7,1,2]
You are given a key to search. If key is found...
Find first non repeated character in a string in Java.
in
Interviews,
Strings
- on 03:11:00
- No comments

Find first non repeated character in a string in Java.
Given a string, find the first non-repeating character in it.
Lets see sample input and output:
...
Find largest number in Binary Search Tree which is less than or equal to N
in
Algorithm,
Binary Search Tree,
Datastructure,
Interviews
- on 01:01:00
- No comments

Largest number in Binary Search Tree which is less than or equal to N.
We have a binary search tree and a number N. Our goal is to find the greatest number in the binary search tree that is less than or equal to N. Print -1 if the the value of the...
Check if a Binary Tree is a Mirror Image or Symmetric in Java.
in
Algorithm,
Binary Tree,
Datastructure,
Interviews
- on 00:31:00
- No comments

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