Pergunta de entrevista da empresa Meta

A set of values given: Assume table in SQL or list of dictionaries if using Python. Basically a row of data contained information: if it is post or it is a comment, row id and some other data. Find distribution of comments. #comments # posts 1 5000 2 6787 .. ..

Respostas da entrevista

Sigiloso

15 de out. de 2017

Can also be with join, but I did it like this: SELECT Count(a.parent_id), num_com FROM (SELECT id AS parent_id, 0 AS num_com FROM submission WHERE parent_id IS NULL AND id NOT IN (SELECT parent_id FROM submission WHERE parent_id IS NOT NULL) UNION SELECT parent_id, Count(id) AS num_com FROM submission WHERE parent_id IS NOT NULL GROUP BY parent_id) AS a GROUP BY num_com;

Sigiloso

15 de out. de 2017

For the above solution, assuming 1 table : submission {id, body, parent_id}

Sigiloso

19 de nov. de 2017

I really think that the question is much simpler than this that Tide understood. Because if this problem wants the distribution of comments and posts and there is this information in the table (the guy said above), we just need to count... I also believe that the distribution per day, or month, etc. SELECT DAY(date) as per_day, content_type, count(content_type) FROM t_post_comment GROUP BY per_day, content_type

Sigiloso

29 de nov. de 2018

From the way the question is worded here, it seems like these are the (relevant) variables in the table (table name - tableA) 1) type ('Comment', 'Post') 2) post_id Seems like each row with 'Comment' entry will have a corresponding 'post_id' to identify which post it was a comment to. Also each 'post' will have a corresponding 'post_id' There may be user_id as well in the table, but let's keep things simple here. Sql code to get #comments # posts select comment_count, count(distinct post_id) as post_count from ( select post_id, count(case when type = 'Comment' then 1 else 0 end) as comment_count from tableA group by post_id ) group by comment_count