Maximal Rectangle

Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area. Example: Input: [ ["1","0","1","0","0"], ["1","0","1","1","1"], ["1","1","1","1","1"], ["1","0","0","1","0"] ] Output: 6 Solution C# Program public class Solution { public int MaximalRectangle(char[][] matrix) { if(matrix == null || matrix.Length == 0) return 0; int row = … Continue reading Maximal Rectangle

Largest Rectangle in Histogram

Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram. Above is a histogram where width of each bar is 1, given height = [2,1,5,6,2,3]. The largest rectangle is shown in the shaded area, which has area = 10 unit. Example: Input: [2,1,5,6,2,3] Output: … Continue reading Largest Rectangle in Histogram

4Sum II

Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero. To make problem a bit easier, all A, B, C, D have same length of N where 0 ≤ N ≤ 500. All integers are in the range … Continue reading 4Sum II

Climbing Stairs

You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Note: Given n will be a positive integer. Example 1: Input: 2 Output: 2 Explanation: There are two ways to climb to the top. … Continue reading Climbing Stairs

Count Square Submatrices with All Ones

Given a m * n matrix of ones and zeros, return how many square submatrices have all ones. Example 1: Input: matrix = [   [0,1,1,1],   [1,1,1,1],   [0,1,1,1] ] Output: 15 Explanation: There are 10 squares of side 1. There are 4 squares of side 2. There is 1 square of side 3. Total number of squares … Continue reading Count Square Submatrices with All Ones

Insert Delete GetRandom O(1)

Hi Geeks! In this article, we going to see about how to insert, delete and get random elements with O(1) Time Complexity. Design a data structure that supports all following operations in average O(1) time. insert(val): Inserts an item val to the set if not already present.remove(val): Removes an item val from the set if present.getRandom: Returns a … Continue reading Insert Delete GetRandom O(1)

Cousins in Binary Tree

In a binary tree, the root node is at depth 0, and children of each depth k node are at depth k+1. Two nodes of a binary tree are cousins if they have the same depth, but have different parents. We are given the root of a binary tree with unique values, and the values x and y of two different nodes in the tree. Return true if and only … Continue reading Cousins in Binary Tree

Diagonal Traverse II

Hi Geeks ! Welcome to 100 days of Leetcode challenge. Day 57 of 100 Given a list of lists of integers, nums, return all elements of nums in diagonal order as shown in the below images. Example 1: Input: nums = [[1,2,3],[4,5,6],[7,8,9]] Output: [1,4,2,7,5,3,8,6,9] Example 2: Input: nums = [[1,2,3,4,5],[6,7],[8],[9,10,11],[12,13,14,15,16]] Output: [1,6,2,8,7,3,9,4,12,10,5,13,11,14,15,16] Example 3: Input: nums = [[1,2,3],[4],[5,6,7],[8],[9,10,11]] Output: … Continue reading Diagonal Traverse II

First Unique Number

You have a queue of integers, you need to retrieve the first unique integer in the queue. Implement the FirstUnique class: FirstUnique(int[] nums) Initializes the object with the numbers in the queue.int showFirstUnique() returns the value of the first unique integer of the queue, and returns -1 if there is no such integer.void add(int value) insert value to the queue. Example 1: Input: ["FirstUnique","showFirstUnique","add","showFirstUnique","add","showFirstUnique","add","showFirstUnique"] [[[2,3,5]],[],[5],[],[2],[],[3],[]] Output: [null,2,null,2,null,3,null,-1] … Continue reading First Unique Number

C# Program to find Minimum Depth of Binary Tree

Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. Note: A leaf is a node with no children. Example: Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 return its minimum depth = … Continue reading C# Program to find Minimum Depth of Binary Tree

Sum of Left Leaves Iterative and Recursive Approach

Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24. Solution DFS Approach - Recursive /** * Definition for a binary tree node. * public class … Continue reading Sum of Left Leaves Iterative and Recursive Approach

How to Validate Binary Search Tree

Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key.The right subtree of a node contains only nodes with keys greater than the node's key.Both the left and right subtrees must also … Continue reading How to Validate Binary Search Tree

How to find the Height and Diameter of the Binary Tree

Hi friends, in this article, we going to see about how to find the height and diameter of Binary Tree. Height of Binary Tree Before finding the diameter of Binary Tree, we must have basic knowledge of how to find the Height of binary tree. Look at the below problem to find the Height(Maximum Depth) … Continue reading How to find the Height and Diameter of the Binary Tree

Binary Tree Zigzag Level Order Traversal

Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example:Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 return its zigzag level order traversal as: [ [3], [20,9], [15,7] ] Solution Level … Continue reading Binary Tree Zigzag Level Order Traversal

Binary Tree Paths

Given a binary tree, return all root-to-leaf paths. Note: A leaf is a node with no children. Example: Input: 1 / \ 2 3 \ 5 Output: ["1->2->5", "1->3"] Explanation: All root-to-leaf paths are: 1->2->5, 1->3 DFS Straight Forward Approach /** * Definition for a binary tree node. * public class TreeNode { * public int … Continue reading Binary Tree Paths

Group Anagrams

Given an array of strings, group anagrams together. Example: Input: ["eat", "tea", "tan", "ate", "nat", "bat"], Output: [ ["ate","eat","tea"], ["nat","tan"], ["bat"] ] Note: All inputs will be in lowercase.The order of your output does not matter. Leetcode 6th day challenge C# Program Solution - Easy to Understand public class Solution { public IList<IList<string>> GroupAnagrams(string[] strs) { … Continue reading Group Anagrams

Reverse Substrings Between Each Pair of Parentheses

Introduction Hi friends! Welcome to 100 Days of Leetcode Challenge. In this article, we going to see about Reverse Substrings Between Each Pair of Parentheses. Language I took C# programming language to solve this problem. Since language is independent of the problem. You can use whatever language you wish to solve. Only problem solving approach(logic) … Continue reading Reverse Substrings Between Each Pair of Parentheses

Alphabet Board Path

INTRODUCTION In this article, we will see about Alphabet Board Path. It is one of the interesting problem, find Alphabet Board Path. BACKGROUND Day 14 of 100 Days of Leetcode Programming Challenge. This is one of the top Leetcode Problem. This problem tests our logical skills. LANGUAGE I took C# programming language to solve this … Continue reading Alphabet Board Path

How to Reorganize String?

INTRODUCTION In this article, we will see about How to Reorganize String? It is one of the interesting problem, Reorganizing string. Background Day 13 of 100 Days of Leetcode Programming Challenge. This is one of the top Leetcode Problem. This problem tests our knowledge in string manipulations and hashing. Related Problems Top K Frequent ElementsHow … Continue reading How to Reorganize String?

How to Sort Characters By Frequency?

Introduction In this article, we will see about How to sort characters based upon frequency? Background Day 12 of 100 Days of Leetcode Programming Challenge. This is one of the top Leetcode Problem. This problem tests our knowledge in Map data structure and Sorting. Language I took C# programming language to solve this problem. Since … Continue reading How to Sort Characters By Frequency?

Evaluate Reverse Polish Notation

Hi Geeks! Welcome to 100 Days of Leetcode Challenge. Day 4 Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. Note: Division between two integers should truncate toward zero.The given RPN expression is always valid. That means the expression would always evaluate … Continue reading Evaluate Reverse Polish Notation

Difference between string and String in C#

In this article, we will learn about what is the difference between string and String in C#. In C#, string is an alias for the String class in .NET. In fact, every C# type has an equivalent in .NET. As another example, short and int in C# map to Int16 and Int32  in .NET. In C#, string is a class. Both string and String class comes from … Continue reading Difference between string and String in C#

C# Program to Validate IP Address

Hi geeks, in this article we going to see about the Leetcode's Validate Ip Address Problem. This is one of the important interview question. There are different ways to solve this problem like Naive Approach, Straight Forward Approach, etc. But I solved this problem in a efficient way by using Microsoft framework's packages like System.Net, … Continue reading C# Program to Validate IP Address

ZigZag Conversion

The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I I G Y I R And then read line by line: "PAHNAPLSIIGYIR" Write the code that will take … Continue reading ZigZag Conversion

C# Program to Reverse Integer

Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Note:Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows. Required … Continue reading C# Program to Reverse Integer

The Complete C# tutorials

Get ready folks! The Complete C# tutorials is coming very soon with high quality content and detailed explanations! What is C#? History of C# Java vs C# Environment Setup C# Program Structure C# Variables and Data types C# Value and Reference Types C# Control Statements C# Keywords C# Functions C# Arrays C# Class and Objects … Continue reading The Complete C# tutorials

Constructors in C#

This article explains about Constructors, types of Constructors and why we need Constructors in a class. Every class requires a constructor to create a instance of that class. It is a special method present in the class. To initialize the variables of the class, we need Constructor. The name of the constructor should be same … Continue reading Constructors in C#

Reverse string in C#

Hi Geeks! This is a little pretty interesting question. How to reverse the string in C#? There are different ways available in C# to reverse the string. In this article, I'm going to discuss with you. Come on, Let's examine that different ways. Input: "Developers Inspired" Output: "deripnsI srepoleveD" Our input and output is above😍 … Continue reading Reverse string in C#

Multidimensional Arrays in C#

These are special types of arrays. It is very useful when you want to deal with the data that is grid-like in nature. Declaring and initializing the two dimensional array is simple. We have to put "," inside the square bracket. One comma between the square bracket indicates 2D array. Two commas between the square … Continue reading Multidimensional Arrays in C#

Copying Arrays in C#

Arrays offer very rich functionality in terms of methods and properties to perform higher level tasks. In this article, we going to see about very popular and important method in Arrays. Array implements many methods and properties itself, so that we can do copying the array, rearranging the elements in it and finding particular elements. … Continue reading Copying Arrays in C#

C# Arrays

Array is a data structure. Array is used to store collection of data. We can store the integers, strings, decimal values in an array. It stores the values in continuous memory location. An array has fixed size in nature. By using index we can access the array elements. The lowest index indicates the first element … Continue reading C# Arrays

History of C#

Do you want to know the interesting history of C#?