Implement String Compression
Implement string compression.
Input: chars = ["a","b","b","b","b","b","b","b","b","b","b","b","b"]
Output: ["a","b","1","2"]
Explanation: The letter 'a' appears once (so no number is appended), and 'b' appears 12 times, modifying the array in place to length 4.
Merge two sorted arrays into one sorted array.
You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. Merge them into a single array sorted in non-decreasing order.
Input: nums1 = [0], m = 0, nums2 = [1], n = 1
Outp…
Find the K closest points to the origin.
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).
Input: points = [[3,3],[5,-1],[-2,4]], k = 2
Output: [[3,3], [-2,4]]
Explanation: The squared distances are 18, 26, and 20 respectively. Th…