一亩三分地论坛

 找回密码
 获取更多干货,去instant注册!

扫码关注一亩三分地公众号
查看: 1754|回复: 3
收起左侧

[其他] 一个小公司的面试题

[复制链接] |试试Instant~ |关注本帖
muancy 发表于 2016-1-17 02:25:32 | 显示全部楼层 |阅读模式

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看,没有帐号?获取更多干货,去instant注册!

x
Please write Java code with mysql queries (as needed) for these 2 very simple problems. Note, try to have syntactically correct code.

Problem 1 :
You have a table called member which has 3 columns email, age_as_integer, gender - email is the primary key and age value is integer like 20, 30 , 40, 41, etc

a. We want to find out in this table which age has the most number of members
so let's say we have 50 records with age 20, and 60 with age 21, and 55 with age 23 and so on you need to get the answer 21 given that is the age for most number of members.

b. As a next step, we want to find a band of 5 years where we have most number of profiles so it can be age 1 to age 5 or age 2 to age 6 or age 15 to age 20 - any band of 5 yrs
where we have the most number of profiles (note number of members in a particular 5 year band are the sum of count of profiles associated with per year in that band of 5 years)


Problem 2 :

Write code to find elements in an array of integers that are not only duplicates but that are within 4 array index apart so in an example array of (1, 3, 4, 1, 2, 6, 1, 9, 8, 3)
we will get 1 as answer but not 3 because although 3 is duplicate the occurrence happens at more than 4 indices apart

求问大家,这个sql要怎么写~
本人只会写第一题的a
谢谢大家~~
samparly 发表于 2016-1-17 09:17:32 | 显示全部楼层
第二题用hashmap就搞定了呀,复杂度o(n)。有什么时间空间要求吗
回复 支持 反对

使用道具 举报

googlerr 发表于 2016-1-17 13:23:33 | 显示全部楼层
第2题似乎是LeetCode原题:https://leetcode.com/problems/contains-duplicate-ii/
回复 支持 反对

使用道具 举报

chaosMonkey 发表于 2016-9-27 14:25:41 | 显示全部楼层
第二题时固定长度的窗口类问题吧,用set记录索引,维护长度为4,在范围内看看有没有重复就好了。
回复 支持 反对

使用道具 举报

本版积分规则

请点这里访问我们的新网站:一亩三分地Instant.

Instant搜索更强大,不扣积分,内容组织的更好更整洁!目前仍在beta版本,努力完善中!反馈请点这里

关闭

一亩三分地推荐上一条 /5 下一条

手机版|小黑屋|一亩三分地论坛声明 ( 沪ICP备11015994号 )

custom counter

GMT+8, 2016-12-10 03:56

Powered by Discuz! X3

© 2001-2013 Comsenz Inc. Design By HUXTeam

快速回复 返回顶部 返回列表