Add Binary
Given two binary strings a and b, return their sum as a binary string.
Given two binary strings a and b, return their sum as a binary string.
Given two non-negative integers, num1 and num2 represented as string, return the sum of num1 and num2 as a string.
---
4-20
You have n coins and you want to build a staircase with these coins.
Given an integer array nums of 2n integers, group these integers into n pairs (a1, b1), (a2, b2), ..., (an, bn)
Assume you are an awesome parent and want to give your children some cookies.
Always a balanced tree
Check if a string contains properly nested and balanced parentheses, and false if otherwise.
You are given an array prices where prices[i] is the price of a given stock on the ith day.
You are given an integer array prices where prices[i] is the price of a given stock on the ith day.
---
Given a binary string s and a positive integer n, return true if the binary representation of all the integers
---
Given an array of integers preorder, which represents the preorder traversal of a BST (i.e., binary search tree),
Maintains bucket of 0..9 or a-z
Given two strings s and goal, return true if you can swap two letters in s so the result is equal to goal,
You have a long flowerbed in which some of the plots are planted, and some are not.
You are climbing a staircase. It takes n steps to reach the top.
Assume that we are given n pairs of items as input, where the first item is a
Suppose an array A consists of n elements, each of which is red, white, or blue.
Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai).
Given an integer array nums, return true if any value appears at least twice in the array,
Given an integer array nums and an integer k, return true if there are two distinct indices i and j
Given an integer num, return a string representing its hexadecimal representation.
Find Convex Hull - a polygon that surrounds all points
The count-and-say sequence is a sequence of digit strings defined by the recursive formula:
Given the root of a complete binary tree, return the number of the nodes in the tree.
Given an integer n, return an array ans of length n + 1 such that for each i (0 <= i <= n),
Given the root of a binary tree with unique values and the values of two different nodes of the tree x and y,
You are given two strings order and s. All the words of order are unique
You are given a search string and a magazine.
Given an array of integers temperatures represents the daily temperatures, return an array answer
Given a string date representing a Gregorian calendar date formatted as YYYY-MM-DD, return the day number of the year.
Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements.
Design a HashMap without using any built-in hash table libraries:
Implement MyHashSet class:
Source – Gist
We define the usage of capitals in a word to be right when one of the following cases holds:
Given the root of a binary tree, return the length of the diameter of the tree.
---
Given two integers dividend and divisor, divide two integers without using multiplication, division, and mod operator.
---
Given an integer columnNumber, return its corresponding column title as it appears in an Excel sheet.
NO need to sort all the items.
Given two strings s and p, return an array of all the start indices of p's anagrams in s.
Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive.
Find the range in which [str] occurs in [array].
You are given two strings s and t.
Given unbounded 0s followed by unbounded number of 1s, find the first index of transition.
Suppose you have n versions [1, 2, ..., n] and you want to find out the first bad one,
Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1.
---
While Dijkstra Shortest Path algorithm helps find shortest path between start and end vertex, [FloydWarshallAlgorithm]
Algorithm to find the max flow to the sink in a given [network]
Given a phone number should format in the form of abc-def-ijk. Last two part can be of 2 digits
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
Given array of integers, generate its permutations.
Bit method – Each subset of n elements can be represented as sequences of n bits Backtrack method
---
Depth First Traversal Breadth First Traversal
Greatest common divisor using Euclidean Algorithm
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
Write an algorithm to determine if a number n is happy.
---
Given two binary tree, find if they are identical i.e. same value at the same position & same structure
How does insertion sort work?
Given an integer, convert it to a roman numeral.
Two lines (P1, P2) and (P3,P4) intersect when orientation of:
Given two integer arrays nums1 and nums2, return an array of their intersection.
---
Given two strings s and t, return true if s is a subsequence of t, or false otherwise.
You are given row x col grid representing a map where gridi = 1 represents land and gridi = 0 represents water.
Given two strings s and t, determine if they are isomorphic.
Design the CombinationIterator class:
Given an array of integers nums and an integer k, return the number of unique k-diff pairs in the array.
Give an O(n log k)-time algorithm that merges k sorted lists with a total of n
Given a set S of n integers and an integer T,
K-d tree is a binary search tree with more than 1 dimensions (i.e k dimensions).
Given an array of strings words, return the words that can be typed
Knapsack Problem: Given total capacity [totalCapacity] of a bag,
Given a set of distinct positive integers nums, return the largest subset answer
---
Given a string s consisting of some words separated by some number of spaces, return the length of the last word in the string.
Given an integer array nums, return the length of the longest strictly increasing subsequence.
Given a string containing digits from 2-9 inclusive, return all possible
You are given a license key represented as a string s that consists of only alphanumeric characters and dashes.
Given a number of lines, find the lines that intersects with each other
Given head, the head of a linked list, determine if the linked list has a cycle in it.
---
Suppose we have a file system that stores both files and directories.
Write a function to find the longest common prefix string amongst an array of strings.
Given an integer array nums, return the longest strictly increasing subsequence.
[4-33] Algorithm to determine whether there exists an i index such as ai = i given array of {a1, a2, a3 ... an}
Given an array nums of size n, return the majority element.
---
You are given an m x n binary matrix grid. An island is a group of 1's (representing land)
Given the root of a binary tree, return its maximum depth.
Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible.
Given an integer array nums, find a contiguous non-empty subarray within the array that has the largest product,
Given an integer array nums, find the contiguous subarray (containing at least one number)
Merge two sorted linked lists and return it as a sorted list.
Merge two sorted linked lists and return it as a sorted list.
Given a singly-linked list, find its middle node.
Minimum Deletions to Make Character Frequencies Unique
---
Suppose Andy and Doris want to choose a restaurant for dinner,
Given a string s consisting only of characters 'a', 'b', and 'c'.
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
Given a triangle array, return the minimum path sum from top to bottom.
Given an array nums containing n distinct numbers in the range [0, n],
Given an integer array nums, move all 0's to the end of it while maintaining
You have an unordered array X of n integers. Find the array M containing
Given a target T and a set of points S, find the nearest neighbour of T in S.
---
The next greater element of some element x in an array is the first greater element that is to the right of x in the same array.
Given a circular integer array nums (i.e., the next element of nums[nums.length - 1] is nums[0]),
You are playing the following Nim Game with your friend:
Design a data structure that allows one to search, insert, and delete an integer
Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight).
Construct a DS with search, remove and add operations of O(1) in worst case
---
Link
Write a function that checks whether an integer is a palindrome.
Let A[1..n] be an array of real numbers. Design an algorithm to perform any
Let A be an array of n real numbers. Design an algorithm to perform any sequence of the following operations:
Given an integer numRows, return the first numRows of Pascal's triangle.
Given an integer rowIndex, return the rowIndexth (0-indexed) row of the Pascal's triangle.
Given the root of a binary tree and an integer targetSum,
---
Calculate the pivot index of this array.
You are given a large integer represented as an integer array digits, where each digits[i]
Given an integer n, return true if it is a power of four. Otherwise, return false.
Solution//www.programiz.com/dsa/prim-algorithm
Prim Algorithm starts from min cost edge and then selects the next small cost edge
https://algs4.cs.princeton.edu/92search/QuadTree.java.html
Implement the RandomizedSet class:
Given an integer array nums, handle multiple queries of the following type:
Given an integer array nums, handle multiple queries of the following types:
Given two stings ransomNote and magazine, return true if ransomNote can be constructed from magazine and false otherwise.
An n x n grid is composed of 1 x 1 squares where each 1 x 1 square consists of a '/', '\', or blank space ' '.
Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place.
Given the head of a sorted linked list, delete all duplicates such
You are given the head of a singly linked-list. The list can be represented as L0 → L1 → … → Ln - 1 → Ln
Given a string s, check if it can be constructed by taking a substring of it and appending
You are given an m x n matrix mat and two integers r and c
A valid IP address consists of exactly four integers separated by single dots.
Reverse bits of a given 32 bits unsigned integer.
link here
You are given an array that contains an expression in Reverse Polish Notation.
Reverse the words in a sentence—i.e., “My name is Chris” becomes “Chris is name My.”
Write a function that reverses a string. The input string is given as an array of characters s.
Given a string s and an integer k, reverse the first k characters for every 2k characters counting
Given a string s, reverse only all the vowels in the string and return it.
You are given a character array containing a set of words separated by whitespace.
Given a string s, reverse the order of characters in each word within a sentence
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.
You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise).
Given the roots of two binary trees p and q, write a function to check if they are the same or not.
---
Given a sorted array of distinct integers and a target value,
Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of
Identify the smallest element from unsorted portion and put it at the end of the sorted portion
You have a set of integers s, which originally contains all the numbers from 1 to n.
---
Given an integer n, return a list of all simplified fractions between 0 and 1 (exclusive)
You are given a sorted array consisting of only integers where every element appears exactly twice,
Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.
Given an integer array nums where every element appears three times except for one, which appears exactly once.
Given an integer array nums, in which exactly two elements appear only once and
[4-34]
Suppose that we are given a sequence of n values x1, x2, ..., xn and seek to
Given a string s, sort it in decreasing order based on the frequency of the characters.
Given the head of a linked list, return the list after sorting it in ascending order.
Given an m x n matrix, return all elements of the matrix in spiral order.
Given a positive integer n, generate an n x n matrix filled with elements from 1 to n^2 in spiral order.
Given a non-negative integer x, compute and return the square root of x.
Implement a last-in-first-out (LIFO) stack using only two queues.
Find substring match
---
Given the root of a binary tree, return the sum of all left leaves.
You are given the root of a binary tree containing digits from 0 to 9 only.
You are given a sorted unique integer array nums.
Given an m x n matrix board containing 'X' and 'O',
Given a linked list, swap every two adjacent nodes and return its head.
Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).
Given an integer array nums, return the third distinct maximum number
Given an integer array nums of length n and an integer target, find three integers in nums such that the sum is closest to target.
Given an integer array nums and an integer k, return the k most frequent elements.
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
---
O(nlogn) algorithm for finding whether there exists a pair of elements, one from S1 and one
Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order,
An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5.
Union-Find represent each subset as backward trees
A robot is located in the top-left corner of a m x n grid (marked 'Start' in the diagram below).
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).
---
Given two strings s and t, return true if t is an anagram of s, and false otherwise.
Given a string s, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
Design a data structure that supports adding new words and finding if a string matches any previously added string.
Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a
Given a pattern and a string s, find if s follows the same pattern.
Given an m x n grid of characters board and a string word, return true if word exists in the grid.
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: