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

Leetcode 379: Design Phone Directory

Design a phone directory that initially has maxNumbers empty slots that can store numbers. The directory should store numbers, check if a certain slot is empty or not, and empty a given slot. Implement the PhoneDirectory class: PhoneDirectory(int maxNumbers) Initializes the phone directory with the number of available slots maxNumbers.int get() Provides a number that ...

Leetcode 370: Range Addition

You are given an integer length and array updates where updates[i] = [startIdxi, endIdxi, inci]. You have an array “arr” of length with all zeros, and you have some operation to apply on arr. In the ith operation, you should increment all the elements arr[startIdxi], arr[startIdxi + 1], …, arr[endIdxi] by inci. Return arr after ...

Leetcode 1056: Confusing Number

A confusing number is a number that, when rotated 180 degrees, becomes a different number with each digit valid. We can rotate the digits of a number by 180 degrees to form new digits. When 0, 1, 6, 8, and 9 are rotated 180 degrees, they become 0, 1, 9, 8, and 6, respectively.When 2, ...