## Java Program to Solve Sliding Window Maximum Problem

Sliding Window Maximum problem is a question that is asked in different companies like Google, Amazon & Walmart. You will find the question in websites like LeetCode and InterviewBit.   An array of integers A is given to us. We have a sliding window of size B which is moving from the left of the … Read more

## Working Java Program For Largest Rectangle in Histogram

Problem: An array of integers A is given of size N. A represents a histogram i.e A[i] denotes height of the ith histogramâ€™s bar. Width of each bar is 1. This is a question you will find in LeetCode or InterviewBit and asked in interviews of Google, Amazon or Facebook. Above you can see  a histogram with … Read more

## Java Code Implementation For All Unique Permutations

This is a common question asked in interviews of Microsoft, Google & Facebook. You might have stumbled upon this question in LeetCode or InterviewBit. Given a collection of numbers that might contain duplicates, return all possible unique permutations. Input: nums = [1,1,2] Output: [[1,1,2],  [1,2,1],  [2,1,1]] Here is the working solution for this problem in … Read more

## Evaluate Reverse Polish Notation In Java

Here is a fully working Java solution for evaluation of Reverse Polish Notation (Postfix Expression). This is a common interview question that is asked in Google, Yahoo and Facebook. Solution Java class doesn’t have a main() method. You can write a main() method and call evalRPN() method from there. Input argument to evalRPN() method should … Read more

## Java Program To Sort A Linked List

Here is the fully working Java code solution for sorting a Linked List. You can find the same problem as an exercise in LeetCode. I have used Merge Sort here. The expectation here is that the code should run in O(n log n) time complexity and space complexity should be O(1). The below java program … Read more

## Quick Sort Implementation In Java

Quick Sort is a notable sorting algorithm. I will try to explain Quick Sort in simple terms. Let’s take an example: Input: 12 25 14 30 15 Output: 12 14 15 25 30 Suppose we have an unsorted array [12, 25, 14, 30, 15] as mentioned above. We will sort the unsorted array using Quick … Read more

## Working Merge Sort Implementation In Java

Should I write an article explaining Merge Sort? There are tons of articles or videos online which explain Merge Sort. What new am I going to add? This is what I thought initially. But after a bit of hesitation, I have decided to write a post on Merge Sort. I would try to explain it … Read more

## Building Binary Heap In O(n) Worst Time Complexity Explained

There are two ways we can build a binary heap, top-down & bottom-up. We will take top-down approach first. Let’s consider the max heap below. For top-down approach we will start from the root & then move the node towards the bottom till max heap property is satisfied. As you can see from screenshot, heap … Read more

## How To Find Recurring Sequence In A Fraction

We are here to solve a LeetCode problem “166. Fraction to Recurring Decimal“. The problem states that: Given two integers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part is repeating, enclose the repeating part in parentheses. Non-repeating Sequence Example: Input: numerator = 1, denominator = … Read more