Leetcode 57: Insert Interval

https://leetcode.com/problems/insert-interval/description/ You are given an array of non-overlapping intervals intervals where intervals[i] = [starti, endi] represent the start and the end of the ith interval and intervals is sorted in ascending order by starti. You are also given an interval newInterval = [start, end] that represents the start and end of another interval. Insert newInterval into intervals such that intervals is still sorted in ascending order by starti and intervals still does not have any overlapping ...

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 452: Minimum Number of Arrows to Burst Balloons

There are some spherical balloons taped onto a flat wall that represents the XY-plane. The balloons are represented as a 2D integer array points where points[i] = [xstart, xend] denotes a balloon whose horizontal diameter stretches between xstart and xend. You do not know the exact y-coordinates of the balloons. Arrows can be shot up directly vertically (in the positive y-direction) from different points along the ...

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