由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 看到一个题目
相关主题
One question on Careercup问到算法题和一道c++题
C++ 程序求助同学们, 看看这几行code有区别吗>
Google 面试题 一道sum nested list 我连题目都没看懂T_T 求解答
bit manipulation 小题Google电话面试题目
Ask a amazon question from careercup.问一道题
请大家谈谈应对简单题目的策略吧Search in a sorted, rotated list
k-selection algorithm本版mj pdf合集
问一道老题问道面试题
相关话题的讨论汇总
话题: arr话题: int话题: integers话题: size话题: 数字
进入JobHunting版参与讨论
1 (共1页)
b****p
发帖数: 216
1
今天在careercup上看到一个题目。Given an unordered array of positive integers
, create an algorithm that makes sure no group of integers of size bigger
than M have the same integers.
想到的死办法就是统计每个数字的个数之后放到一个heap里面去,每次取最大的一个,
要是连续取了M次了,就取第二大的。每次可以比较一下剩下的最大数目的数字k和所有
剩下来的元素n。 如果k比 n/(M+1)*M大的话就直接fail..
不知道还有什么好办法没有
c******0
发帖数: 260
2
我不是很清楚LZ到底要怎么处理多出来的数字。我是把多余的数字跟最后一个数字交换
,然后数组大小减一。所以没有保障顺序。如果用vector,就可以直接删除。
int deleteExtra(int arr[], int size, int M){
unordered_map track;
int start = 0, end = M;
for(int i=0; i track[ arr[i] ]++;

while(end < size){
if( track[ arr[end] ] == M){
swap( arr[end], arr[--size]);
}else{
track[ arr[start++] ]--;
track[ arr[end++] ]++;
}
}
for(int k=0; k cout< cout< return size;
}
b****p
发帖数: 216
3
112222 m=2就不行了吧。

【在 c******0 的大作中提到】
: 我不是很清楚LZ到底要怎么处理多出来的数字。我是把多余的数字跟最后一个数字交换
: ,然后数组大小减一。所以没有保障顺序。如果用vector,就可以直接删除。
: int deleteExtra(int arr[], int size, int M){
: unordered_map track;
: int start = 0, end = M;
: for(int i=0; i: track[ arr[i] ]++;
:
: while(end < size){
: if( track[ arr[end] ] == M){

x****g
发帖数: 1512
4
算法目标是啥?group数最少?

integers

【在 b****p 的大作中提到】
: 今天在careercup上看到一个题目。Given an unordered array of positive integers
: , create an algorithm that makes sure no group of integers of size bigger
: than M have the same integers.
: 想到的死办法就是统计每个数字的个数之后放到一个heap里面去,每次取最大的一个,
: 要是连续取了M次了,就取第二大的。每次可以比较一下剩下的最大数目的数字k和所有
: 剩下来的元素n。 如果k比 n/(M+1)*M大的话就直接fail..
: 不知道还有什么好办法没有

c******0
发帖数: 260
5
我的输出时 1,1,2,2
不知道LZ想输出什么。。。

【在 b****p 的大作中提到】
: 112222 m=2就不行了吧。
1 (共1页)
进入JobHunting版参与讨论
相关主题
问道面试题Ask a amazon question from careercup.
Given an array of N integers from range [0, N] and one is missing. Find the missing number.请大家谈谈应对简单题目的策略吧
G题一道(1)k-selection algorithm
Careercup question.问一道老题
One question on Careercup问到算法题和一道c++题
C++ 程序求助同学们, 看看这几行code有区别吗>
Google 面试题 一道sum nested list 我连题目都没看懂T_T 求解答
bit manipulation 小题Google电话面试题目
相关话题的讨论汇总
话题: arr话题: int话题: integers话题: size话题: 数字