[LeetCode] Find K Closest Elements

658. Find K Closest Elements

Given a sorted integer array arr, two integers k and x, return the k closest integers to x in the array. The result should also be sorted in ascending order.

An integer a is closer to x than an integer b if:

  • |a - x| < |b - x|, or
  • |a - x| == |b - x| and a < b
Read more
[LeetCode] Sequentially Ordinal Rank Tracker

2102. Sequentially Ordinal Rank Tracker

A scenic location is represented by its name and attractiveness score, where name is a unique string among all locations and score is an integer. Locations can be ranked from the best to the worst. The higher the score, the better the location. If the scores of two locations are equal, then the location with the lexicographically smaller name is better.

You are building a system that tracks the ranking of locations with the system initially starting with no locations. It supports:

  • Adding scenic locations, one at a time.
  • Querying the ith best location of all locations already added, where i is the number of times the system has been queried (including the current query).
  • For example, when the system is queried for the 4th time, it returns the 4th best location of all locations already added.

Note that the test data are generated so that at any time, the number of queries does not exceed the number of locations added to the system.

Implement the SORTracker class:

  • SORTracker() Initializes the tracker system.
  • void add(string name, int score) Adds a scenic location with name and score to the system.
  • string get() Queries and returns the ith best location, where i is the number of times this method has been invoked (including this invocation).
Read more
[Code Jam 2022 Round 1B] ASeDatAbRead more
[Code Jam 2022 Round 1B] Controlled InflationRead more
[Code Jam 2022 Round 1B] Pancake DequeRead more
[BOJ] 17402 시간 끌기Read more
[BOJ] 2316 도시 왕복하기 2Read more
[BOJ] 11378 열혈강호 4Read more
[BOJ] 17412 도시 왕복하기 1Read more
[BOJ] 14286 간선 끊어가기 2Read more