Solved! Leetcode 953: Verifying an Alien Dictionary

Source: https://leetcode.com/problems/verifying-an-alien-dictionary/description/ In an alien language, surprisingly, they also use English lowercase letters, but possibly in a different order. The order of the alphabet is some permutation of lowercase letters. Given a sequence of words written in the alien language, and the order of the alphabet, return true if and only if the given words ...

Solved! Leetcode 1109: Corporate Flight Bookings

source: https://leetcode.com/problems/corporate-flight-bookings/description/ There are n flights that are labeled from 1 to n. You are given an array of flight bookings bookings, where bookings[i] = [firsti, lasti, seatsi] represents a booking for flights firsti through lasti (inclusive) with seatsi seats reserved for each flight in the range. Return an array answer of length n, where ...

Solved! Leetcode 734: Sentence Similarity

Sentence Similarity We can represent a sentence as an array of words, for example, the sentence "I am happy with leetcode" can be represented as arr = ["I","am",happy","with","leetcode"]. Given two sentences sentence1 and sentence2 each represented as a string array and given an array of string pairs similarPairs where similarPairs[i] = [xi, yi] indicates that ...

Solved! Leetcode 2359: Find Closest Node to Given Two Nodes

You are given a directed graph of n nodes numbered from 0 to n – 1, where each node has at most one outgoing edge. The graph is represented with a given 0-indexed array edges of size n, indicating that there is a directed edge from node i to node edges[i]. If there is no ...

Solved! Leetcode 1626: Best Team With No Conflicts

Table of ContentsBest Team: Problem StatementJavaPython Best Team: Problem Statement You are the manager of a basketball team and your task is to form a best team. For the upcoming tournament, you want to choose the team with the highest overall score. The score of the team is the sum of scores of all the ...

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