## LeetCode – Sort Characters By Frequency

Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: “tree” Output: “eert” Explanation: ‘e’ appears twice while ‘r’ and ‘t’ both appear

Skip to content
## LeetCode – Sort Characters By Frequency

## LeetCode – Count Square Submatrices with All Ones

## LeetCode – Kth Smallest Element in a BST

## LeetCode – Online Stock Span

## LeetCode – Permutation in String

## LeetCode – Find All Anagrams in a String

## LeetCode – Odd Even Linked List

## LeetCode – Maximum Sum Circular Subarray

## LeetCode – Implement Trie (Prefix Tree)

## LeetCode – Remove K Digits

## LeetCode – Single Element in a Sorted Array

## LeetCode – Flood Fill

## LeetCode – Find the Town Judge

## LeetCode – Valid Perfect Square

## LeetCode – Check If It Is a Straight Line

## LeetCode – Cousins in Binary Tree

## LeetCode – Majority Element

## LeetCode – First Unique Character in a String

## LeetCode – Number Complement

## LeetCode – Ransom Note

## LeetCode – Jewels and Stones

## LeetCode – First Bad Version

## LeetCode – Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree – 30Days Challenge

## LeetCode – Binary Tree Maximum Path Sum – 30Days Challenge

## LeetCode – Maximal Square – 30Days Challenge

## LeetCode – Leftmost Column with at Least a One – 30Days Challenge

## LeetCode – Construct Binary Search Tree from Preorder Traversal – 30Days Challenge

## LeetCode – Search in Rotated Sorted Array – 30Days Challenge

## LeetCode – Valid Parenthesis String – 30Days Challenge

## LeetCode – Contiguous Array – 30Days Challenge

## LeetCode – Last Stone Weight – 30Days Challenge

## LeetCode – Bitwise AND of Numbers Range – 30Days Challenge

## LeetCode – First Unique Number – 30Days Challenge

## LeetCode – Backspace String Compare – 30Days Challenge

## LeetCode – Perform String Shifts – 30Days Challenge

## LeetCode – Happy Number – 30Days Challenge

## LeetCode – Best Time to Buy and Sell Stock II – 30Days Challenge

## LeetCode – Product of Array Except Self – 30Days Challenge

## LeetCode – Longest Common Subsequence – 30Days Challenge

## LeetCode – Minimum Path Sum – 30Days Challenge

## LeetCode – Diameter of Binary Tree – 30Days Challenge

## LeetCode – Min Stack – 30Days Challenge

## LeetCode – Middle of the Linked List – 30Days Challenge

## LeetCode – Counting Elements – 30Days Challenge

## LeetCode – Jump Game – 30Days Challenge

## LeetCode – Number of Islands – 30Days Challenge

## LeetCode – Subarray Sum Equals K – 30Days Challenge

## LeetCode – Group Anagrams – 30Days Challenge

## LeetCode – LRU Cache – 30Days Challenge

## LeetCode – Move Zeroes – 30Days Challenge

## LeetCode – Maximum Subarray – 30Days Challenge

## LeetCode – Single Number – 30Days Challenge

## Convert a Binary Tree into its Mirror Tree

## ZigZag Level Order Traversal BT

## Postorder Tree Traversal

## Preorder Tree Traversal

## Inorder Tree Traversal

## LeetCode – Circular Permutation in Binary Representation (Java)

## Check if Binary trees are Symmetric or Not

## How to check if two Trees are Identical or Not?

## LeetCode – Two Sum IV – Input is a BST

## LeetCode – Validate IP Address

## LeetCode – Reverse Words in a String

## Find pair with given difference K in the array

## Find Path with Maximum Gold

## Largest Continuous Sub Array with Zero Sum – Java

## Colorful Number

## LeetCode – Minimum Absolute Difference

## Given an Array of Integers and Target Number, Find Pair having Sum as Target

## Group all anagrams from a given array of Strings

## Towers Of Hanoi Algorithm

## Selection Sort Algorithm

## Quick Sort Algorithm

## Merge Sort Algorithm

## Insertion Sort Algorithm

## Linear or Sequential Search Algorithm

## Bubble Sort Algorithm

## Binary Search Algorithm

a source of knowledge.

Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: “tree” Output: “eert” Explanation: ‘e’ appears twice while ‘r’ and ‘t’ both appear

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]

Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Example 1: Input: root = [3,1,4,null,2], k = 1 3 / \ 1

Write a class StockSpanner which collects daily price quotes for some stock, and returns the span of that stock’s price for the current day. The span of the stock’s price today is

Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string’s permutations is the

Given a string s and a non-empty string p, find all the start indices of p‘s anagrams in s. Strings consists of lowercase English letters only and the length of

Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in

Given a circular array C of integers represented by A, find the maximum possible sum of a non-empty subarray of C. Here, a circular array means the end of the array connects to the beginning

Implement a trie with insert, search, and startsWith methods. Example: Trie trie = new Trie(); trie.insert(“apple”); trie.search(“apple”); // returns true trie.search(“app”); // returns false trie.startsWith(“app”); // returns true trie.insert(“app”); trie.search(“app”);

Given a non-negative integer num represented as a string, remove k digits from the number so that the new number is the smallest possible. Note: The length of num is

You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once. Find this single element that appears only

An image is represented by a 2-D array of integers, each integer representing the pixel value of the image (from 0 to 65535). Given a coordinate (sr, sc) representing the

In a town, there are N people labelled from 1 to N. There is a rumor that one of these people is secretly the town judge. If the town judge exists, then:

Given a positive integer num, write a function which returns True if num is a perfect square else False. Note: Do not use any built-in library function such as sqrt.

You are given an array coordinates, coordinates[i] = [x, y], where [x, y] represents the coordinate of a point. Check if these points make a straight line in the XY plane. Example

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

Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array

Given a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1. Examples: s = “leetcode” return 0. s = “loveleetcode”, return

Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation. Example 1: Input: 5 Output: 2 Explanation: The binary representation

Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from

You’re given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have.

You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is

Given a binary tree where each path going from the root to any leaf form a valid sequence, check if a given string is a valid sequence in such binary tree.

Given a non-empty binary tree, find the maximum path sum. For this problem, a path is defined as any sequence of nodes from some starting node to any node in

Given a 2D binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s and return its area. Example: Input: 1 0 1 0 0 1 0

(This problem is an interactive problem.) A binary matrix means that all elements are 0 or 1. For each individual row of the matrix, this row is sorted in non-decreasing order. Given a row-sorted binary matrix

Return the root node of a binary search tree that matches the given preorder traversal. (Recall that a binary search tree is a binary tree where for every node, any descendant

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]). You are given a target value to search. If

Given a string containing only three types of characters: ‘(‘, ‘)’ and ‘*’, write a function to check whether this string is valid. We define the validity of a string

Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1. Example 1: Input: [0,1] Output: 2 Explanation: [0, 1] is the

We have a collection of stones, each stone has a positive integer weight. Each turn, we choose the two heaviest stones and smash them together. Suppose the stones have weights x and y

Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive. Example 1: Input: [5,7] Output: 4

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

Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character. Note that after backspacing an empty text, the text will continue

You are given a string s containing lowercase English letters, and a matrix shift, where shift[i] = [direction, amount]: direction can be 0 (for left shift) or 1 (for right shift). amount is the amount by which

Write an algorithm to determine if a number n is “happy”. A happy number is a number defined by the following process: Starting with any positive integer, replace the number

Say you have an array prices for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You

Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except

Given two strings text1 and text2, return the length of their longest common subsequence. A subsequence of a string is a new string generated from the original string with some

Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note:

Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. 1. push(x) — Push element x onto stack. 2. pop() — Removes the element

Given a non-empty, singly linked list with head node head, return a middle node of linked list. If there are two middle nodes, return the second middle node. Example 1: Input: [1,2,3,4,5] Output:

Given an integer array arr, count element x such that x + 1 is also in arr. If there’re duplicates in arr, count them seperately. Example 1: Input: arr = [1,2,3]

Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position.

Given a 2d grid map of ‘1’s (land) and ‘0’s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally

Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k. Example 1: Input:nums = [1,1,1], k

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

Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put. get(key) – Get the value (will always be positive)

Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements. Example: Input: [0,1,0,3,12] Output: [1,3,12,0,0]

Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. Example: Input: [-2,1,-3,4,-1,2,1,-5,4], Output: 6 Explanation: [4,-1,2,1]

Given a non-empty array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it

Given a binary tree, invert the binary tree and return it. Look at the example for more details. Mirror of a Tree: Mirror of a Binary Tree T is another

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

Given a binary tree, return the post-order traversal of its nodes’ values. For traversing a binary tree in post-order fashion, we must do these three things for every node N

Given a binary tree, return the pre-order traversal of its nodes’ values. For traversing a binary tree in pre-order fashion, we must do these three things for every node N

Given a binary tree, return the inorder traversal of its nodes’ values. For traversing a binary tree in in-order fashion, we must do these three things for every node N

Given 2 integers n and start. Your task is return any permutation p of (0,1,2…..,2^n -1) such that : p[0] = start p[i] and p[i+1] differ by only one bit

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).Return 0 / 1 ( 0 for false, 1 for true ) for this

Given two binary trees, write a function to check if they are equal or not. “Two binary trees are considered equal if they are structurally identical and the nodes have

Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target. Example

Write a function to check whether an input string is a valid IPv4 address or IPv6 address or neither. IPv4 addresses are canonically represented in dot-decimal notation, which consists of

Given an input string, reverse the string word by word. Example 1: Input: “the sky is blue” Output: “blue is sky the” Example 2: Input: ” hello world! ” Output:

Given an array A of integers and another non-negative integer K, find if there exist 2 indices i and j such that A[i] – A[j] = K, i != j.

In a gold mine grid of size m * n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is

Find the largest continuous sequence in an array which sums to zero. Example: Input: { 1 , 3 , -1 , 2 , -4 , 1} Output: {3 , -1

For Given Number N find if its COLORFUL number or not Number is COLORFUL number if product of every digit of a contiguous subsequence is different. A number can be

Given an array of distinct integers arr[], find all pairs of elements with the minimum absolute difference of any two elements. Return a list of pairs in ascending order(with respect

Given an array of integers A[], find two numbers such that they add up to a specific target number B. The program should return indices of the two numbers such

Given an array of strings, return all groups of strings that are anagrams. Represent a group by a list of integers representing the index in the original list. Look at

Towers Of Hanoi Algorithm The towers of hanoi is a mathematical puzzle. We have three towers (or rods or pegs), and a number of disks of different sizes which can

Selection Sort Algorithm Selection sort is a sorting algorithm, specifically an in-place comparison sort. It has O(n2) time complexity, making it inefficient on large lists, and generally performs worse than

Quick Sort Algorithm Quick sort (sometimes called partition-exchange sort) is an efficient sorting algorithm. It is a commonly used algorithm for sorting. When implemented well, it can be about two

Merge Sort Algorithm Merge sort algorithm is an efficient, comparison-based sorting algorithm. Most implementations produce a stable sort, which means that the implementation preserves the input order of equal elements

Insertion Sort Algorithm Insertion sort algorithm is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It is much less efficient on

Linear or Sequential Search Algorithm Linear or sequential search algorithm is a method for finding a target value within a list. It sequentially checks each element of the list for

Bubble Sort Algorithm Bubble sort algorithm, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of

Binary Search Algorithm Binary search algorithm requires already sorted collection. Binary search, (also known as half-interval search, logarithmic search, or binary chop) is a search algorithm that finds the position