HN user

kkdaemas

397 karma
Posts15
Comments35
View on HN

The question is very unrealistic... how often do you know there is exactly one duplicate in a list?

Much more common is there are zero or more duplicates.

Here is what I came up with:

- We need a way to record what has been already seen

- A hash-map could work, but I think we can be more efficient

- We know that all elements are less than the array length in size...

- So we can allocate a single array of flags with the same length as the input

- The flag for value `n` is at position `n` in this array

    let findDuplicates xs =
      let seen = Array.create (Seq.length xs) false

      let mutable duplicates = []

      for x in xs do
        if seen[x] then
          duplicates <- x :: duplicates
        else
          seen[x] <- true

      duplicates
I'm pretty sure this is O(n)?

I think it's interesting that the mathematical trick (sum of numbers 1 to n formula) does not work in the more realistic variant. This fact is probably why leet-code problems are so disconnected from the real world. It's like AI for board-games.

GraphQL Is a Trap? 4 years ago

It's not that GraphQL enables anything that was not possible before; it's that GraphQL provides a bit more structure and standardization around these things. If you plan to do this stuff, why not follow something with a spec and various bits of tooling rather than doing it ad-hoc?

We won't really know until the election, but for what it's worth opinion polls have Johnson down compared to when he started his term.

Interesting that you came to this view. Boris seems to have handled COVID incredibly poorly (e.g. the death rate in the UK is higher than comparable countries) and the trade deal is considerably worse than deals he previously rejected (e.g. customs border inside the UK). I expect that once the world stabilizes again, members of his own party will want to take his job.

Not a very original concept. They use these puzzles for child intelligence tests. Are the puzzles automatically generated?

What would be hilarious (imo) would be if the 100th puzzle is actually unsolvable.

implementing the hard things on C or C++

This misses the point. I don't care how the language implements the functionality if it meets my performance requirements and it is convenient to use.

This is a very short sighted view. Police forces cannot maintain order in the event of massive unrest and the best way to prevent this is to keep people above the poverty line and the death rates low. Desperation leads to upheaval.