# 📰 “I think I can. I think I can. I think I can. I know I can.” - Watty Piper

The Coding Puzzle 🧩

Last week’s puzzle:

Given a positive integer N, returns the length of its longest binary gap. The function should return 0 if N doesn’t contain a binary gap.

Examples:

Given N = 1041 the function should return 5, because N has binary representation 10000010001 and so its longest binary gap is of length 5.

Given N = 32 the function should return 0, because N has binary representation ‘100000’ and thus no binary gaps.

Solution for last week’s problem:

N = 1041 br = str(bin(N))[2:] def solution(N, br): br_group = False br_highest = 0 bin_zero_counter = 0 for char in br: if char == '1': br_group = False bin_zero_counter = 0 elif char == '0': br_group = True bin_zero_counter += 1 if br_highest < bin_zero_counter: br_highest = bin_zero_counter print('Binary output is: ', br, 'highest gap is: ', br_highest) if N==32: print('100000 has no binary gaps') else: solution(N, br)

This week’s puzzle:

Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same.

starter code:

class Solution: def removeDuplicates(self, nums: List[int]) -> int:

Example 1:

Input: nums = [1,1,2] Output: 2, nums = [1,2,_ ] Explanation: Your function should return k = 2, with the first two elements of nums being 1 and 2 respectively. It does not matter what you leave beyond the returned k (hence they are underscores).

Example 2:

Input: nums = [0,0,1,1,1,2,2,3,3,4]
Output: 5, nums = [0,1,2,3,4,*,*,*,*,_]
Explanation: Your function should return k = 5, with the first five elements of nums being 0, 1, 2, 3, and 4 respectively.
It does not matter what you leave beyond the returned k (hence they are underscores).

Developer Shares & Headlines 📢

❇️ The Linux Foundation Open Source Summit

❇️ Some developers are Frustrated

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