📣 独立日限时特惠: VIP通行证立减$68
查看: 3384| 回复: 3
跳转到指定楼层
上一主题 下一主题
收起左侧

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

全局:

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

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

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
谢谢大家~~

上一篇:再开一帖暴力刷题
下一篇:Topcoder无法注册怎么破。。
🔗
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,在范围内看看有没有重复就好了。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

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