Solved! Leetcode 491: Non-decreasing Subsequences

https://leetcode.com/problems/non-decreasing-subsequences/description/ Given an integer array nums, return all the different possible non-decreasing subsequences of the given array with at least two elements. You may return the answer in any order. Example 1: Input: nums = [4,6,7,7] Output: [[4,6],[4,6,7],[4,6,7,7],[4,7],[4,7,7],[6,7],[6,7,7],[7,7]] class Solution { public List<List<Integer>> findSubsequences(int[] nums) { Set<List<Integer>> res = new HashSet<>(); helper(nums, 0, new ArrayList<>(), res); return new ...

Solved! Leetcode 1533: Find the Index of the Large Integer

https://leetcode.com/problems/find-the-index-of-the-large-integer/description/ We have an integer array arr, where all the integers in arr are equal except for one integer, which is larger than the rest of the integers. You will not be given direct access to the array. Instead, you will have an API ArrayReader which have the following functions: int compareSub(int l, int r, int x, int y): where 0 <= l, r, ...

Leetcode 1061: Lexicographically Smallest Equivalent String

https://leetcode.com/problems/lexicographically-smallest-equivalent-string/description/ You are given two strings of the same length s1 and s2 and a string baseStr. We say s1[i] and s2[i] are equivalent characters. For example, if s1 = "abc" and s2 = "cde", then we have 'a' == 'c', 'b' == 'd', and 'c' == 'e'. Equivalent characters follow the usual rules of any equivalence relation: Reflexivity: 'a' == 'a'.Symmetry: 'a' == 'b' implies 'b' == 'a'.Transitivity: 'a' == 'b' and 'b' == 'c' implies 'a' == ...

Leetcode 1519: Number of Nodes in the Sub-Tree With the Same Label

You are given a tree (i.e., a connected, undirected graph that has no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. The root of the tree is the node 0, and each node of the tree has a label which is a lower-case character given in the string labels (i.e., The node with the number i has the label labels[i]). The edges array is given ...

Leetcode 1443: Minimum Time to Collect All Apples in a Tree

Given an undirected tree consisting of n vertices numbered from 0 to n-1, which has some apples in their vertices. You spend 1 second to walk over one edge of the tree. Return the minimum time in seconds you have to spend to collect all apples in the tree, starting at vertex 0 and coming back to this vertex. The edges of the ...

Leetcode 2214: Minimum Health to Beat Game

You are playing a game that has n levels numbered from 0 to n - 1. You are given a 0-indexed integer array damage where damage[i] is the amount of health you will lose to complete the ith level. You are also given an integer armor. You may use your armor ability at most once during the game on any level, which will protect you from at most armor damage. You must complete the levels in ...

Solved! Leetcode 100: Same Tree

Table of ContentsJava SolutionPython Solution Given the roots of two binary trees p and q, write a function to check if they are the same or not. Two binary trees are considered to be same trees if they are structurally identical and the nodes have the same value. Example 1. Input: p = [1,2,3], q = [1,2,3]Output: trueExample ...

Leetcode 2244: Minimum Rounds to Complete All Tasks

You are given a 0-indexed integer array tasks, where tasks[i] represents the difficulty level of a task. In each round, you can complete either 2 or 3 tasks of the same difficulty level. Return the minimum rounds required to complete all the tasks, or -1 if it is not possible to complete all the tasks. Example 1: <strong>Input:</strong> tasks = [2,2,3,3,2,4,4,4,4,4] <strong>Output:</strong> 4 <strong>Explanation:</strong> To complete ...

Leetcode 944: Delete Columns to Make Sorted

You are given an array of n strings strs, all of the same lengths. The strings can be arranged such that there is one on each line, making a grid. For example, strs = ["abc", "bce", "cae"] can be arranged as: abc bce cae You want to <strong>delete</strong> the columns that are <strong>not sorted lexicographically</strong>. In the above example (0-indexed), columns 0 (<code>'a'</code>, <code>'b'</code>, <code>'c'</code>) ...

Solved! Leetcode 520: Detect Capital

We define the usage of capitals in a word to be right when one of the following cases holds: All letters in this word are capitals, like "USA". All letters in this word are not capitals, like "leetcode". Only the first letter in this word is capitalized, like "Google". Given a string “word”, return true if the usage of capitals ...