hachyderm.io is one of the many independent Mastodon servers you can use to participate in the fediverse.
Hachyderm is a safe space, LGBTQIA+ and BLM, primarily comprised of tech industry professionals world wide. Note that many non-user account types have restrictions - please see our About page.

Administered by:

Server stats:

9.5K
active users

Šimon Tóth

Tuesday common C++ interview problem: Find the singular number.

Given a sorted array of integers as std::vector<int>, where all values are present twice except for one singular number, return the singular number.

Your solution must run in O(logn) and use O(1) memory.

Solve it yourself: compiler-explorer.com/z/q6GbnE
Solution: compiler-explorer.com/z/Pf9h4P

@aurisc4 That definitely wouldn't be log(n).

@simontoth don't do it linear. Xor each pair, loop until one itm is left :)

@aurisc4 That would actually be n*log(n).

@simontoth yeah, sorted is better with binary search indeed. On a big list.