Section mcq’s choice Choice Choice 1,2 Choice 1,3,5
Download 63.22 Kb.
|
CODER EXAM
Response 1 – 4,4,4,4,1,1
Response 2 – 3,4,3,3,1,1 I have a timeseriesdataframe and want to drop the last period of data for all items, how do I do this? Response 1 – Response 2 – SECTION 3 WRITING Re-Write: Q1 Instructions The purpose of the re-write is to improve the base response as much as possible, so that it would be graded as a 5 using the writing rubrics. This includes, but is not limited to, fixing all spelling and grammar mistakes, fixing / improving / adding content and adding references. Make sure your response includes reasoning and rationale for any edits made Prompt Consider an array of integer pairs, 'centers', representing the coordinates of people on a map at a specific moment. Each person is enclosed in a square box with sides of length 2. For two person to meet, it means their boxes share at least one common point. Write code in python to calculate the number of pairs of people that can meet. To determine if two boxes intersect, you should check that the absolute differences between the x-coordinates and y-coordinates of the object centers do not exceed 2 in both dimensions. In other words, if x1, y1 are the coordinates of one person, and x2, y2 are the coordinates of the second person, the condition can be expressed as: | x1 - x2 | <= 2 | y1 - y2 | <= 2 For example, if given the 'centers' array as input with coordinates [[1,1], [2,2], [0,4]], the output is 2. This means that there are two pairs of people who will meet. Please improve the model's response by rewriting or editing it Sure! Here's the function I wrote in python: ```python def number_of_collisions(centers): d = defaultdict(int) ans = 0 for i in range(len(centers)): for j in range(i + 1, len(centers)): x1, y1 = centers[i] x2, y2 = centers[j] if abs(x1 - x2) <= 2 and abs(y1 - y2) <= 2: ans += 1 ans = ans // 2 for k in d:
return ans ``` Let me know if you have other questions! Answer Download 63.22 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling