Skip to content

Offline Algorithm

Table of Contents

2343. Query Kth Smallest Trimmed Number

  • LeetCode | LeetCode CH (Medium)

  • Tags: array, string, divide and conquer, sorting, heap priority queue, radix sort, quickselect

2070. Most Beautiful Item for Each Query

2070. Most Beautiful Item for Each Query - C++ Solution
#include <algorithm>
#include <iostream>
#include <numeric>
#include <ranges>
#include <vector>
using namespace std;

vector<int> maximumBeauty(vector<vector<int>>& items, vector<int>& queries) {
    ranges::sort(items, {}, [](auto& item) { return item[0]; });
    vector<int> idx(queries.size());
    iota(idx.begin(), idx.end(), 0);
    ranges::sort(idx, {}, [&](int i) { return queries[i]; });

    vector<int> res(queries.size());
    int max_beauty = 0, j = 0;
    for (int i : idx) {
        int q = queries[i];
        while (j < items.size() && items[j][0] <= q) {
            max_beauty = max(max_beauty, items[j][1]);
            j++;
        }
        res[i] = max_beauty;
    }
    return res;
}

int main() {
    vector<vector<int>> items = {{1, 2}, {2, 4}, {3, 2}, {5, 6}, {3, 5}};
    vector<int> queries = {1, 2, 3, 4, 5, 6};
    vector<int> res = maximumBeauty(items, queries);
    // 2 4 5 5 6 6
    for (int i : res) {
        cout << i << " ";
    }
    cout << endl;
    return 0;
}

1847. Closest Room

2503. Maximum Number of Points From Grid Queries

  • LeetCode | LeetCode CH (Hard)

  • Tags: array, two pointers, breadth first search, union find, sorting, heap priority queue, matrix

1851. Minimum Interval to Include Each Query

  • LeetCode | LeetCode CH (Hard)

  • Tags: array, binary search, line sweep, sorting, heap priority queue

1697. Checking Existence of Edge Length Limited Paths

2940. Find Building Where Alice and Bob Can Meet

  • LeetCode | LeetCode CH (Hard)

  • Tags: array, binary search, stack, binary indexed tree, segment tree, heap priority queue, monotonic stack

2747. Count Zero Request Servers

1938. Maximum Genetic Difference Query

  • LeetCode | LeetCode CH (Hard)

  • Tags: array, hash table, bit manipulation, depth first search, trie

2736. Maximum Sum Queries

  • LeetCode | LeetCode CH (Hard)

  • Tags: array, binary search, stack, binary indexed tree, segment tree, sorting, monotonic stack

3382. Maximum Area Rectangle With Point Constraints II

  • LeetCode | LeetCode CH (Hard)

  • Tags: array, math, binary indexed tree, segment tree, geometry, sorting

Comments