Source: Codility

Given an array `A`

of length `n`

filled with integers find the smallest missing positive number.

[4,8,1,3,2] => 5

[1,2] =>3

- n ranges from 1 .. 100,000
- Values of A range from -1,000,000 to 1,000,000

As usual, I decided to first take a brute force approach. As a result, I forced the array into a Set then iteratively checked each number sequentially from 1 to n+1.

functionbrute_force(A) {constaSet =newSet(A)for(leti = 1; i <= aSet.size + 1; i++) { if (!aSet.has(i)) {returni } } }

This worked well. The next task was to think about how to make it work faster. The worst-case scenario would be all positive natural numbers from 1 to n with no missing numbers since we’d have to check every number.

I thought we could possibly squeeze a few milliseconds by `reducing`

A to a positive only `set`

but honestly, the constructor is plenty fast so there was no visible benefit. In the end, I didn’t find another way to get this to go faster so I decided to see how the brute-force method faired.

Turns out, very well. It passed all performance tests with flying colors. So I guess that’s that. 🤷

Today we disemvowel a string. That word is beautiful and means to remove every vowel out of a string. Disemvowel it!

Today I take a break from reading and tackle the simple problem of counting bits in Rust. This is my first Rust solution.

Today I’m looking at functions and loops. They are an important part of any language and deserve a closer look.

Today I take a look at Rust variables and data types. It’s a gentle introduction to a language not too alien from JavaScript.

Today I take a look at cargo, Rust’s answer to npm and yarn. It’s a tool that makes a developer’s life that much easier.