LeetCode Binary Tree Maximum Path Sum [124. Binary Tree Maximum Path Sum] Given a 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 the tree along the parent-child connections. The path must contain at least one node and

LeetCode Sliding Window Maximum 239. Sliding Window Maximum [https://leetcode.com/problems/sliding-window-maximum/] Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window

LeetCode Text Justification 68. Text Justification [https://leetcode.com/problems/text-justification/] Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified. You should pack your words in a greedy approach; that is, pack as many words

LeetCode Binary Tree Longest Consecutive Sequence Binary Tree Longest Consecutive Sequence [https://leetcode.com/problems/binary-tree-longest-consecutive-sequence/] Given a binary tree, find the length of the longest consecutive sequence path. The path refers to any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The longest consecutive path need

LeetCode Rotate Array 189. Rotate Array [https://leetcode.com/problems/rotate-array] Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4]. Note: Try to

LeetCode Lowest Common Ancestor of a Binary Tree 236. Lowest Common Ancestor of a Binary Tree [https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/] 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 [https://en.wikipedia.org/wiki/Lowest_common_ancestor]: “The lowest common ancestor

LeetCode H-Index II 275. H-Index II [https://leetcode.com/problems/h-index-ii/] Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm? public class Solution { public int hIndex(int[] citations) { if (citations == null || citations.length == 0) { return 0; } int low = 0, high = citations.length -

LeetCode Find All Anagrams in a String 438. Find All Anagrams in a String [https://leetcode.com/problems/find-all-anagrams-in-a-string/] 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 both strings s and p will not be

LeetCode Binary Tree Level Order Traversal 102. Binary Tree Level Order Traversal [https://leetcode.com/problems/binary-tree-level-order-traversal/] LintCode-69.Binary Tree Level Order Traversal [http://www.lintcode.com/en/problem/binary-tree-level-order-traversal] Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example: Given binary tree

LeetCode Word Break II 140. Word Break II [https://leetcode.com/problems/word-break-ii/] Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid dictionary word. You may assume the dictionary does not contain duplicate words.

LeetCode Permutations II Permutations II [https://leetcode.com/problems/permutations-ii/] Given a collection of numbers that might contain duplicates, return all possible unique permutations. For example, [1,1,2] have the following unique permutations: [ [1,1,2], [1,2,1], [2,1,1] ] public class Solution { public List> permuteUnique(int[] nums)

LeetCode Reverse Nodes in k-Group 25. Reverse Nodes in k-Group [https://leetcode.com/problems/reverse-nodes-in-k-group/] Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If the number of nodes is not a multiple of k then left-out nodes in the end should remain as

LeetCode 3Sum 15. 3Sum [https://leetcode.com/problems/3sum/] LintCode-57.3Sum [http://www.lintcode.com/en/problem/3sum] Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.

LeetCode ZigZag Conversion 6. ZigZag Conversion [https://leetcode.com/problems/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

LeetCode Longest Palindromic Substring 5. Longest Palindromic Substring [https://leetcode.com/problems/longest-palindromic-substring/] Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example: Input: "babad" Output: "bab" Note: "aba" is also a valid answer. Example: Input: "cbbd" Output: "bb" public class

LeetCode Median of Two Sorted Arrays 4. Median of Two Sorted Arrays [https://leetcode.com/problems/median-of-two-sorted-arrays/] There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Example 1: nums1 = [1, 3] nums2

LeetCode Number of Connected Components in an Undirected Graph 323. Number of Connected Components in an Undirected Graph [https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph/] Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), write a function to find the number of connected components in an undirected

LeetCode Linked List Random Node 382. Linked List Random Node [https://leetcode.com/problems/linked-list-random-node/] Given a singly linked list, return a random node's value from the linked list. Each node must have the same probability of being chosen. Follow up: What if the linked list is extremely large and its length is unknown to