## LeetCode 22. Generate Parentheses Java Solution And Time Complexity Explanation

Generating all possible combinations of balanced parentheses is a common interview problem & is found in websites like LeetCode & GeeksForGeeks.Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. We are using backtracking to solve this problem. There are two cases where we can proceed to the next recursive … Read more

## Java Program To Solve Maximum Size Rectangle In Binary Matrix

We will solve LeetCode problem “85. Maximal Rectangle” here. The problem states that: Given a rows x cols binary matrix filled with 0‘s and 1‘s, find the largest rectangle containing only 1‘s and return its area. Input: [ 1 1 1 0 0 1 1 0 1 1 1 0 ] Output: 6 Does the … Read more

## Java Program To Solve Word Break Problem

We will solve LeetCode problem “139. Word Break” here. The problem statement is as below: Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words. Note that the same word in the dictionary may be reused multiple times … Read more

## Java Program To Search For A Range In Sorted Array

Here we will solve LeetCode problem “34. Find First and Last Position of Element in Sorted Array“. The problem statement is as below: Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target value. If target is not found in the array, return [-1, -1]. … Read more

## Java Program to Invert the Binary Tree

Inverting a binary tree or mirroring a binary tree is a common interview question. We will solve LeetCode “226. Invert Binary Tree” problem here. The problem statement is as follows: Given the root of a binary tree, invert the tree, and return its root. Input: [1, 2, 3, 4, 5, 6, 7] Output: [1, 3, … Read more

## Java Program to Solve Median of Two Sorted Array Problem

We will solve Median of two sorted arrays problem here. It is a common problem solving question which is asked in interview rounds of companies like Amazon, Google, Microsoft & Goldman Sachs. We will use LeetCode problem “4. Median of Two Sorted Arrays” as example here. The problem states that: Given two sorted arrays nums1 … Read more

## Java Program For Shortest Unique Prefix Problem

Shortest Unique Prefix is an interview question which you can find in websites like GeeksForGeeks & InterviewBit. It is asked in Google interviews. The problem is as follows: Find shortest unique prefix to represent each word in the list.Input: [zebra, dog, duck, dove]Unique Prefix of each word is as below:zebra = zdog = dogduck = … Read more

## Better Explanation Of Order of People Heights Problem And Java Program To Solve It

We will be solving LeetCode problem “406. Queue Reconstruction by Height” here. The problem states that: You are given an array of people, “people“, which are the attributes of some people in a queue (not necessarily in order). Each people[i] = [hi, ki] represents the ith person of height hi with exactly ki other people in front who have a height greater than or … Read more

## Java Program For Sum Root to Leaf Numbers

We will be solving LeetCode problem “129. Sum Root to Leaf Numbers” here. This is a common question which has been asked in interview rounds of Google & Microsoft. Problem definition is as follows: You are given the root of a binary tree containing digits from 0 to 9 only.Each root-to-leaf path in the tree … Read more

## Java Program for Least Common Ancestor Of A Binary Tree

We will solve LeetCode problem “236. Lowest Common Ancestor of a Binary Tree” here. The problem states that: Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p and q … Read more