Leetcode 973: K Closest Points to Origin

Problem Statement Description Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0). The distance between two points on the X-Y plane is the Euclidean distance (i.e., √(x1 - x2)2 + (y1 - y2)2). You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in)....

April 15, 2023 · 3 min · 499 words · Me

Leetcode 169: Majority Element

Problem Statement Description Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array. Examples Example 1: Input: nums = [3,2,3] Output: 3 Example 2: Input: nums = [2,2,1,1,1,2,2] Output: 2 Constraints n == nums.length 1 <= n <= 5 * 104 -109 <= nums[i] <= 109 Key Insights There are many different ways to solve this problem....

January 16, 2023 · 2 min · 249 words · Me