Solved! Leetcode 1402. Reducing Dishes

Table of ContentsProblem DescriptionReducing DishesJavaPython Problem Description source: https://leetcode.com/problems/reducing-dishes/description/ Reducing Dishes A chef has collected data on the satisfaction level of his n dishes. Chef can cook any dish in 1 unit of time. Like-time coefficient of a dish is defined as the time taken to cook that dish including previous dishes multiplied by its ...

Solved! Leetcode 958. Check Completeness of a Binary Tree

Table of ContentsProblem descriptionCheck Completeness of a Binary TreeJavaTime ComplexitySpace ComplexityPythonApproach 1Approach 2 Problem description source: https://leetcode.com/problems/check-completeness-of-a-binary-tree/description/ Check Completeness of a Binary Tree Given the root of a binary tree, determine if it is a complete binary tree. In a complete binary tree, every level, except possibly the last, is completely filled, and all nodes ...

Linked List Components

Title: Linked List Components Source: leetcode.com We are given head, the head node of a linked list containing unique integer values. We are also given the list G, a subset of the values in the linked list. Return the number of connected components in G, where two values are connected if they appear consecutively in ...

Increasing Order Search Tree

Title: Increasing Order Search Tree Source: leetcode.com Given a tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only 1 right child (Increasing order search tree). Example 1: Input: [5,3,6,2,4,null,8,1,null,null,null,7,9] 5 / \ 3 6 ...

Find all Anagrams in a String 2

Title: Custom Sort String Source: leetcode.com Given a string s and a non-empty string p, find all the start indices of p‘s anagrams in s. Strings consists of lowercase English letters only and the length of both strings s and p will not be larger than 20,100. The order of output does not matter. Example ...

Custom Sort String

Title: Custom Sort String Source: leetcode.com S and T are strings composed of lowercase letters. In S, no letter occurs more than once. S was sorted in some custom order previously. We want to permute the characters of T so that they match the order that S was sorted. More specifically, if x occurs before ...

Monotonic Array

Title: Monotonic Array Source: leetcode.com An array is monotonic if it is either monotone increasing or monotone decreasing. An array A is monotone increasing if for all i <= j, A[i] <= A[j]. An array A is monotone decreasing if for all i <= j, A[i] >= A[j]. Return true if and only if the ...

Nth Digit in Whole Numbers

Title: Nth DigitSource: leetcode.com Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, … Note: n is positive and will fit within the range of a 32-bit signed integer (n < 231). Python solution The intuition for the solution is thinking about what’s the ...

Binary Watch Problem

Title: Binary Watch Source: leetcode.com A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59). Each LED represents a zero or one, with the least significant bit on the right. For example, the above binary watch reads “3:25”. Given a ...

Leaf-Similar trees

Title: Leaf-Similar TreesSource: leetcode.com Consider all the leaves of a binary tree. From left to right order, the values of those leaves form a leaf value sequence. For example, in the given tree above, the leaf value sequence is (6, 7, 4, 9, 8). Two binary trees are considered leaf-similar if their leaf value sequence ...