用这种难度的题目面试程序员,给多少时间合适?

2020-09-05 03:17:12 +08:00
 lihongming

Julia conducted a 15 days of learning SQL contest. The start date of the contest was March 01, 2016 and the end date was March 15, 2016.

Write a query to print total number of unique hackers who made at least submission each day (starting on the first day of the contest), and find the hacker_id and name of the hacker who made maximum number of submissions each day. If more than one such hacker has a maximum number of submissions, print the lowest hacker_id. The query should print this information for each day of the contest, sorted by the date.


Input Format

The following tables hold contest data:


Sample Input

For the following sample input, assume that the end date of the contest was March 06, 2016.


Sample Output

2016-03-01 4 20703 Angela 2016-03-02 2 79722 Michael 2016-03-03 2 20703 Angela 2016-03-04 2 20703 Angela 2016-03-05 1 36396 Frank 2016-03-06 1 20703 Angela

Explanation

On March 01, 2016 hackers 20703, 36396, 53473 and 79722 made submissions. There are 4 unique hackers who made at least one submission each day. As each hacker made one submission, 20703 is considered to be the hacker who made maximum number of submissions on this day. The name of the hacker is Angela.

On March 02, 2016 hackers 15758, 20703 and 79722 made submissions. Now 20703 and 79722 were the only ones to submit every day, so there are 2 unique hackers who made at least one submission each day. 79722 made 2 submissions, and name of the hacker is Michael.

On March 03, 2016 hackers 20703, 36396 and 79722 made submissions. Now 20703 and 79722 were the only ones, so there are 2 unique hackers who made at least one submission each day. As each hacker made one submission so 20703 is considered to be the hacker who made maximum number of submissions on this day. The name of the hacker is Angela.

On March 04, 2016 hackers 20703, 44065, 53473 and 79722 made submissions. Now 20703 and 79722 only submitted each day, so there are 2 unique hackers who made at least one submission each day. As each hacker made one submission so 20703 is considered to be the hacker who made maximum number of submissions on this day. The name of the hacker is Angela.

On March 05, 2016 hackers 20703, 36396, 38289 and 62529 made submissions. Now 20703 only submitted each day, so there is only 1 unique hacker who made at least one submission each day. 36396 made 2 submissions and name of the hacker is Frank.

On March 06, 2016 only 20703 made submission, so there is only 1 unique hacker who made at least one submission each day. 20703 made 1 submission and name of the hacker is Angela.

4470 次点击
所在节点    程序员
34 条回复
sgissb1
2020-09-05 14:24:15 +08:00
对我来说给多少时间都一样。原因有两个:
1,英语不好,无法准确理解题目含义
2,考察的知识点不会。(主要不是做这块细分工作的)


但最致命的,还是人类语言障碍问题。
shakoon
2020-09-05 14:39:35 +08:00
@newtype0092 #18 group by hacker_id 得出提交提交次数,最大日期减最小日期得出天数,次数小于天数的那肯定就是某天没提交,不符合条件
newtype0092
2020-09-05 15:18:23 +08:00
@shakoon 这些逻辑如果用程序或者存储过程写看起来很简单,主要是就是想问有什么 SQL 技巧可以简单的算出来,如果全是字查询临时表来回套那感觉这题出得不太行。
519718366
2020-09-05 16:47:53 +08:00
让我想起了大学选修 oracle 数据库,最后考试的时候,最后一道纯英文,心里暗骂了下老师 懒狗,肯定是从哪复制粘贴的。🤪
lihongming
2020-09-05 23:36:09 +08:00
@shakoon 10 分钟能完成确实是高级的,可以说是数据专家了。不过不是专门做数据工作的程序员,对 SQL 应该没那么熟练。这题粗看简单,真做起来会发现挺绕的,要反复 join 、子查询,思路得极其清晰才可能快速做完。

而且这题里还有坑(这也是考察点之一,考察对需求的准确理解),虽然例子已经很明显了,但内测还是很多人掉进去了
Meltdown
2020-09-06 11:29:39 +08:00
hackerrank 的原题啊
levelworm
2020-09-06 22:08:16 +08:00
@newtype0092 只能想到提取名字然后 join 最后筛选的笨办法。。。
lihongming
2020-09-07 00:12:30 +08:00
@Meltdown 没错,这个题就是从那儿 copy 来的。

真正考试的难度与此类似,但不会让你 Google 到原题的 :D
dustinth
2020-09-07 08:08:11 +08:00
不专门刷题的能在半个小时做出来的程序员素质不低了, 取名字那一步会出现并列第一名的情况, 规则没说按照什么逻辑来选择.
lihongming
2020-09-07 08:43:43 +08:00
@dustinth 并列第一的问题有说明


If more than one such hacker has a maximum number of submissions, print the lowest hacker_id.
goodboy95
2020-09-07 10:45:33 +08:00
其他的没啥难度,反正子表套子表,使劲套就完事了。
不过 total number of unique hackers 这个……拿出来单独写好写,和其他的数据一起查的话,感觉这 sql 要爆炸……
goodboy95
2020-09-07 10:52:33 +08:00
@dustinth 并列第一取 id 最小,好像题目和示例 1 已经说明了这点
wercbas2020
2020-09-09 21:34:38 +08:00
今天恰巧做了一下面试题,整整 5 页。连谈话沟通加做题两个小时才做完。到最后一页已经累的不行了。再加上办公室里的人在谈话。最后一道题已经让我大脑难以思考。
所以我觉得你不要考虑做面试题的时间长短。会做就是会做,不会做就是不会做。
只要考试的时候不手机上网查资料就可以。
Meltdown
2020-09-12 18:44:18 +08:00
看了答案,要是知道用子查询来计算列的话就简单,不知道的话就得不停 join 或者套子表

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/704379

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX