The Coding Puzzle 🧩

Last week's puzzle:

Given the array nums, for each nums[i] find out how many numbers in the array are smaller than it. That is, for each nums[i] you have to count the number of valid j's such that j != i and nums[j] < nums[i].

Return the answer in an array.

Example 1:

`Input: nums = [6,5,4,8]`

`Output: [2,1,0,3]`

Example 2:

`Input: nums = [7,7,7,7]`

`Output: [0,0,0,0]`

Solution for last week's problem:

```
from typing import List
class Solution:
def smallerNumbersThanCurrent(self, nums: List[int]) -> List[int]:
result = {}
for i, n in enumerate(sorted(nums)):
if n not in result:
result[n] = i
return [result[n] for n in nums]
```

This week's puzzle:

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 nums1 and nums2 into a single array sorted in non-decreasing order.

The final sorted array should not be returned by the function, but instead be stored inside the array nums1. To accommodate this, nums1 has a length of m + n, where the first m elements denote the elements that should be merged, and the last n elements are set to 0 and should be ignored. nums2 has a length of n.

Example 1:

`Input: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3`

`Output: [1,2,2,3,5,6]`

Explanation: The arrays we are merging are [1,2,3] and [2,5,6].

The result of the merge is [1,2,2,3,5,6] with the underlined elements coming from nums1.

Example 2:

`Input: nums1 = [1], m = 1, nums2 = [], n = 0`

`Output: [1]`

Explanation: The arrays we are merging are [1] and [].

The result of the merge is [1].

Developer Shares & Headlines 📢

❇️ Kubecon

❇️ Tesla AI Day

❇️ Quick Intro To Python 3 for AWS Automation Engineers

Want to recommend someone for our developer spotlight, developer event, or just say hello? Send us an email at yourfriends@devslike.us we want to hear from you!

Social 💻

YouTube | Podcast | Instagram | Website | Twitter

The Cast on Twitter: Terrence | Clarence | JB

Well, that's all we have for this week's issue. A quick reminder to add our Podcast on your favorite platform and subscribe to our YouTube page!

Sincerely,

The DLU Team