Skip to content

Fenwick Tree

Table of Contents

307. Range Sum Query - Mutable

  • LeetCode | 力扣

  • Tags: Array, Design, Binary Indexed Tree, Segment Tree

3072. Distribute Elements Into Two Arrays II

  • LeetCode | 力扣

  • Tags: Array, Binary Indexed Tree, Segment Tree, Simulation

3187. Peaks in Array

1649. Create Sorted Array through Instructions

  • LeetCode | 力扣

  • Tags: Array, Binary Search, Divide And Conquer, Binary Indexed Tree, Segment Tree, Merge Sort, Ordered Set

1626. Best Team With No Conflicts

from typing import List


# DP - LIS
def bestTeamScore(scores: List[int], ages: List[int]) -> int:
    n = len(scores)
    pairs = sorted(zip(scores, ages))  # sort
    dp = [0 for _ in range(n)]

    # LIS
    for i in range(n):
        for j in range(i):
            if pairs[i][1] >= pairs[j][1]:
                dp[i] = max(dp[i], dp[j])
        dp[i] += pairs[i][0]

    return max(dp)


if __name__ == "__main__":
    assert bestTeamScore([1, 3, 5, 10, 15], [1, 2, 3, 4, 5]) == 34
    assert bestTeamScore([4, 5, 6, 5], [2, 1, 2, 1]) == 16

1409. Queries on a Permutation With Key

2250. Count Number of Rectangles Containing Each Point

  • LeetCode | 力扣

  • Tags: Array, Binary Search, Binary Indexed Tree, Sorting

2179. Count Good Triplets in an Array

  • LeetCode | 力扣

  • Tags: Array, Binary Search, Divide And Conquer, Binary Indexed Tree, Segment Tree, Merge Sort, Ordered Set

1395. Count Number of Teams

  • LeetCode | 力扣

  • Tags: Array, Dynamic Programming, Binary Indexed Tree, Segment Tree

2659. Make Array Empty

  • LeetCode | 力扣

  • Tags: Array, Binary Search, Greedy, Binary Indexed Tree, Segment Tree, Sorting, Ordered Set

2653. Sliding Subarray Beauty

1505. Minimum Possible Integer After at Most K Adjacent Swaps On Digits

  • LeetCode | 力扣

  • Tags: String, Greedy, Binary Indexed Tree, Segment Tree

2926. Maximum Balanced Subsequence Sum

  • LeetCode | 力扣

  • Tags: Array, Binary Search, Dynamic Programming, Binary Indexed Tree, Segment Tree

2736. Maximum Sum Queries

  • LeetCode | 力扣

  • Tags: Array, Binary Search, Stack, Binary Indexed Tree, Segment Tree, Sorting, Monotonic Stack

3382. Maximum Area Rectangle With Point Constraints II

  • LeetCode | 力扣

  • Tags: Array, Math, Binary Indexed Tree, Segment Tree, Geometry, Sorting

3245. Alternating Groups III

1756. Design Most Recently Used Queue 👑

  • LeetCode | 力扣

  • Tags: Array, Hash Table, Stack, Design, Binary Indexed Tree, Ordered Set

2519. Count the Number of K-Big Indices 👑

  • LeetCode | 力扣

  • Tags: Array, Binary Search, Divide And Conquer, Binary Indexed Tree, Segment Tree, Merge Sort, Ordered Set

2613. Beautiful Pairs 👑

  • LeetCode | 力扣

  • Tags: Array, Math, Divide And Conquer, Geometry, Sorting, Ordered Set

2921. Maximum Profitable Triplets With Increasing Prices II 👑

308. Range Sum Query 2D - Mutable 👑

  • LeetCode | 力扣

  • Tags: Array, Design, Binary Indexed Tree, Segment Tree, Matrix