ElasticRun Interview Question

breadth-first search algorithm and SQL query to count distinct using group by