Segment Tree

Segment Tree

Twenty-five questions on segment trees, for range queries and updates in logarithmic time.

Fruits Into Baskets II

easy
You are given two arrays of integers, fruits and baskets, each of length n, where fruits[i] represents the quantity of the ith type of fruit, and baskets[j] represents the...

Count Number of Teams

medium
There are n soldiers standing in a line.

Fruits Into Baskets III

medium
You are given two arrays of integers, fruits and baskets, each of length n, where fruits[i] represents the quantity of the ith type of fruit, and baskets[j] represents the...

Maximum Area Rectangle With Point Constraints I

medium
You are given an array points where points[i] = [xi, yi] represents the coordinates of a point on an infinite plane.

Minimum Number of Valid Strings to Form Target I

medium
You are given an array of strings words and a string target.

Number of Longest Increasing Subsequence

medium
Given an integer array nums, return the number of longest increasing subsequences.

Queue Reconstruction by Height

medium
You are given an array of people, people, which are the attributes of some people in a queue (not necessarily in order).

Block Placement Queries

hard
There exists an infinite number line, with its origin at 0 and extending towards the positive x-axis.

Count Good Triplets in an Array

hard
You are given two 0-indexed arrays nums1 and nums2 of length n, both of which are permutations of [0, 1, ..., n - 1].

Count Non-Decreasing Subarrays After K Operations

hard
You are given an array nums of n integers and an integer k.

Count of Range Sum

hard
Given an integer array nums and two integers lower and upper, return the number of range sums that lie in [lower, upper] inclusive.

Count of Smaller Numbers After Self

hard
Given an integer array nums, return an integer array counts where counts[i] is the number of smaller elements to the right of nums[i].

Create Sorted Array through Instructions

hard
Given an integer array instructions, you are asked to create a sorted array from the elements in instructions.

Delivering Boxes from Storage to Ports

hard
You have the task of delivering some boxes from storage to their ports using only one ship.

Distribute Elements Into Two Arrays II

hard
You are given a 1-indexed array of integers nums of length n.

Falling Squares

hard
There are several squares being dropped onto the X-axis of a 2D plane.

Find a Value of a Mysterious Function Closest to Target

hard
Winston was given the above mysterious function func.

Find Building Where Alice and Bob Can Meet

hard
You are given a 0-indexed array heights of positive integers, where heights[i] represents the height of the ith building.

Find Subarray With Bitwise OR Closest to K

hard
You are given an array nums and an integer k.

Find X Value of Array II

hard
You are given an array of positive integers nums and a positive integer k.

Handling Sum Queries After Update

hard
You are given two 0-indexed arrays nums1 and nums2 and a 2D array queries of queries.

Longest Increasing Subsequence II

hard
You are given an integer array nums and an integer k.

Longest Substring of One Repeating Character

hard
You are given a 0-indexed string s.

Make Array Empty

hard
You are given an integer array nums containing distinct numbers, and you can perform the following operations until the array is empty: Return an integer denoting the number of...

Maximize Active Section with Trade II

hard
You are given a binary string s of length n, where: You can perform at most one trade to maximize the number of active sections in s.