Top K Elements

  • K Closest Points to Origin
    Given an array points representing n points in a 2D plane, where points[i] = [x_i, y_i], and an integer k, find the k closest points to the origin (0, 0).The distance between two points on the plane is the Euclidean distance (i.e., sqrt(x^2 + y^2)).Return the k closest points in any order. It is guaranteed that the answer exists.
  • Find K Closest Elements
    Given a sorted integer array arr, two integers x and k, find the k closest elements to x in the array. The result should be sorted in ascending order by the absolute difference between each element and x. If there is a tie, the smaller elements are preferred.
  • Top K Frequent Elements
    Given an integer array nums and an integer k, return the k most frequent elements in the array. If there are multiple elements with the same frequency, return them in any order.
  • Sort Characters By Frequency
    Given a string s, sort the characters in the string based on their frequency in non-increasing order.
  • Kth Largest Element in an Array
    Given an unsorted array of integers and a positive integer k, find the kth largest element in the array.
  • Sort Array by Increasing Frequency
    Given an array nums of integers, you need to sort the array in increasing order based on the frequency of the values. If two values have the same frequency, sort them in decreasing order.
  • Least Number of Unique Integers after K Removals
    Given an array arr of integers and an integer k, you need to find the least number of unique integers after removing exactly k elements from the array.