ElasticRun interview question

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