A scatter-plot widget wants to draw points on a small grid that keeps their left-to-right and bottom-to-top order but drops the distances. The points are [x, y] pairs in points.
Write compressPoints(points) that replaces each x with its 0-based rank among the distinct x values and each y with its 0-based rank among the distinct y values. Return the new pairs in the same order.
Input: points = [[100,5],[3,5],[100,900],[-7,40]] Output: [[2,0],[1,0],[2,2],[0,1]]
The distinct x values in order are -7, 3, 100, and the distinct y values are 5, 40, 900.
Input: points = [] Output: []
No points.
0 <= points.length <= 2 * 10^5-10^9 <= x, y <= 10^9Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #94 Compress Point Coordinates. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.