332. Reconstruct Itinerary

You are given a list of airline tickets where tickets[i] = [fromi, toi] represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it. All of the tickets belong to a man who departs from “JFK”, thus, the itinerary must begin with “JFK”. If there are multiple valid itineraries, you should return the itinerary that has the smallest lexical order when read as a single string....

<span title='2021-11-29 00:00:00 +0000 UTC'>November 29, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

655. Print Binary Tree

Given the root of a binary tree, construct a 0-indexed m x n string matrix res that represents a formatted layout of the tree. The formatted layout matrix should be constructed using the following rules: The height of the tree is height and the number of rows m should be equal to height + 1. The number of columns n should be equal to 2height+1 - 1. Place the root node in the middle of the top row (more formally, at location res[0][(n-1)/2])....

<span title='2021-11-29 00:00:00 +0000 UTC'>November 29, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

267. Palindrome Permutation II

Given a string s, return all the palindromic permutations (without duplicates) of it. You may return the answer in any order. If s has no palindromic permutation, return an empty list. 1 2 3 4 5 6 7 8 9 Example 1: Input: s = "aabb" Output: ["abba","baab"] Example 2: Input: s = "abc" Output: [] Constraints: 1 <= s.length <= 16 s consists of only lowercase English letters. Solution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 class Solution { public List<String> generatePalindromes(String s) { Set<String> res = new HashSet<>(); int[] freq = new int[256]; int count = 0; for (char c : s....

<span title='2021-11-28 00:00:00 +0000 UTC'>November 28, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

409. Longest Palindrome

Given a string s which consists of lowercase or uppercase letters, return the length of the longest palindrome that can be built with those letters. Letters are case sensitive, for example, “Aa” is not considered a palindrome here. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Example 1: Input: s = "abccccdd" Output: 7 Explanation: One longest palindrome that can be built is "dccaccd", whose length is 7....

<span title='2021-11-28 00:00:00 +0000 UTC'>November 28, 2021</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;volyx

266. Palindrome Permutation

Given a string s, return true if a permutation of the string could form a palindrome. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Example 1: Input: s = "code" Output: false Example 2: Input: s = "aab" Output: true Example 3: Input: s = "carerac" Output: true Constraints: 1 <= s.length <= 5000 s consists of only lowercase English letters. Solution 1 2 3 4 5 6 7 8 9 10 11 12 13 class Solution { public boolean canPermutePalindrome(String s) { int[] freq = new int[256]; for (char c: s....

<span title='2021-11-27 00:00:00 +0000 UTC'>November 27, 2021</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;volyx

286. Walls and Gates

You are given an m x n grid rooms initialized with these three possible values. -1 A wall or an obstacle. 0 A gate. INF Infinity means an empty room. We use the value 231 - 1 = 2147483647 to represent INF as you may assume that the distance to a gate is less than 2147483647. Fill each empty room with the distance to its nearest gate. If it is impossible to reach a gate, it should be filled with INF....

<span title='2021-11-27 00:00:00 +0000 UTC'>November 27, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

673. Number of Longest Increasing Subsequence

Given an integer array nums, return the number of longest increasing subsequences. Notice that the sequence has to be strictly increasing. 1 2 3 4 5 6 7 8 9 10 11 Example 1: Input: nums = [1,3,5,4,7] Output: 2 Explanation: The two longest increasing subsequences are [1, 3, 4, 7] and [1, 3, 5, 7]. Example 2: Input: nums = [2,2,2,2,2] Output: 5 Explanation: The length of longest continuous increasing subsequence is 1, and there are 5 subsequences' length is 1, so output 5....

<span title='2021-11-26 00:00:00 +0000 UTC'>November 26, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

126. Word Ladder II

A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> … -> sk such that: Every adjacent pair of words differs by a single letter. Every si for 1 <= i <= k is in wordList. Note that beginWord does not need to be in wordList. sk == endWord Given two words, beginWord and endWord, and a dictionary wordList, return all the shortest transformation sequences from beginWord to endWord, or an empty list if no such sequence exists....

<span title='2021-11-25 00:00:00 +0000 UTC'>November 25, 2021</span>&nbsp;·&nbsp;3 min&nbsp;·&nbsp;volyx

291. Word Pattern II

Given a pattern and a string s, return true if s matches the pattern. A string s matches a pattern if there is some bijective mapping of single characters to strings such that if each character in pattern is replaced by the string it maps to, then the resulting string is s. A bijective mapping means that no two characters map to the same string, and no character maps to two different strings....

<span title='2021-11-25 00:00:00 +0000 UTC'>November 25, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

815. Bus Routes

You are given an array routes representing bus routes where routes[i] is a bus route that the ith bus repeats forever. For example, if routes[0] = [1, 5, 7], this means that the 0th bus travels in the sequence 1 -> 5 -> 7 -> 1 -> 5 -> 7 -> 1 -> … forever. You will start at the bus stop source (You are not on any bus initially), and you want to go to the bus stop target....

<span title='2021-11-24 00:00:00 +0000 UTC'>November 24, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

249. Group Shifted Strings

We can shift a string by shifting each of its letters to its successive letter. For example, “abc” can be shifted to be “bcd”. We can keep shifting the string to form a sequence. For example, we can keep shifting “abc” to form the sequence: “abc” -> “bcd” -> … -> “xyz”. Given an array of strings strings, group all strings[i] that belong to the same shifting sequence. You may return the answer in any order....

<span title='2021-11-23 00:00:00 +0000 UTC'>November 23, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

76. Minimum Window Substring

Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicates) is included in the window. If there is no such substring, return the empty string “”. The testcases will be generated such that the answer is unique. A substring is a contiguous sequence of characters within the string. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Example 1: Input: s = "ADOBECODEBANC", t = "ABC" Output: "BANC" Explanation: The minimum window substring "BANC" includes 'A', 'B', and 'C' from string t....

<span title='2021-11-23 00:00:00 +0000 UTC'>November 23, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

921. Minimum Add to Make Parentheses Valid

A parentheses string is valid if and only if: It is the empty string, It can be written as AB (A concatenated with B), where A and B are valid strings, or It can be written as (A), where A is a valid string. You are given a parentheses string s. In one move, you can insert a parenthesis at any position of the string. For example, if s = “()))”, you can insert an opening parenthesis to be “(()))” or a closing parenthesis to be “())))”....

<span title='2021-11-23 00:00:00 +0000 UTC'>November 23, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

257. Binary Tree Paths

Given the root of a binary tree, return all root-to-leaf paths in any order. A leaf is a node with no children. 1 2 3 4 5 6 7 8 9 Example 1: Input: root = [1,2,3,null,5] Output: ["1->2->5","1->3"] Example 2: Input: root = [1] Output: ["1"] Constraints: The number of nodes in the tree is in the range [1, 100]. -100 <= Node.val <= 100 Solution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 /** * Definition for a binary tree node....

<span title='2021-11-22 00:00:00 +0000 UTC'>November 22, 2021</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;volyx

47. Permutations II

Given a collection of numbers, nums, that might contain duplicates, return all possible unique permutations in any order. 1 2 3 4 5 6 7 8 9 10 11 12 Example 1: Input: nums = [1,1,2] Output: [[1,1,2], [1,2,1], [2,1,1]] Example 2: Input: nums = [1,2,3] Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] Constraints: 1 <= nums.length <= 8 -10 <= nums[i] <= 10 Solution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 class Solution { public List<List<Integer>> permuteUnique(int[] nums) { List<List<Integer>> res = new ArrayList<>(); permuteAt(0, nums, res); return res; } void permuteAt(int i, int[] nums, List<List<Integer>> res) { if (i == nums....

<span title='2021-11-22 00:00:00 +0000 UTC'>November 22, 2021</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;volyx