Blog

Candidate Key Takeaways (2019 kakao)

Published 1 min read

Coding Test Practice - Candidate Key

  1. Iterating over every combination

Getting all 2^N combinations of consecutive numbers with bitmasking

for (int i=0; i < (1 << n); i++) cout << i;
  1. Property of the iteration

If we assume it's set A's turn,
every subset of A has already been processed.

  1. Checking if bits are a subset

For bits a, b,
if a & b == a,
then a is a subset of b.

  1. Watch out with string keys

When there are several strings,
you sometimes concatenate all the strings into one string, store it in a map,
and use it as a key.
In that case you need to put a separator like a space in between.
Otherwise you can get a counterexample where "a", "a", "bc" and "aa", "b", "c" end up with the same key "aabc".

Comments

Leaving a comment stores your nickname (or GitHub profile info). Privacy policy

GitHub