一亩三分地论坛

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

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

[找工就业] Follow up 以前Azumo 的OA 回报一下地里

[复制链接] |试试Instant~ |关注本帖
丢丢棠线 发表于 2015-12-11 11:40:59 | 显示全部楼层 |阅读模式

2015(7-9月)-[]CS硕士+fresh grad 无实习/全职 - 网上海投| 码农类全职@Azumofresh grad应届毕业生

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

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

x
今天刚做了Azumo 给的OA。三道题都是Array 总共110分钟 平台是codility提交完了直接评分 有一道题是妥妥跪了,不知道会不会有回音了。
第一题很简单 一个数组找数组A[p]-A[Q] 叫做distance。求数组的最短距离。. From 1point 3acres bbs
第二题
An integer X and a non-empty zero-indexed array A consisting of N integers are given. We are interested in which elements of A are equal to X and which are different from X. The goal is to split array A into two parts, such that the number of elements equal to X in the first part is the same as the number of elements different from X in the other part. More formally, we are looking for an index K such that: 0 ≤ K < N and the number of elements equal to X in A[0..K−1] is the same as the number of elements different from X in A[K..N−1]. For K = 0, A[0..K−1] does not contain any elements.

For example, given integer X = 5 and array A such that:A = [5, 5, 1, 7, 2, 3, 5]K equals 4,

要求最坏时间O(n) space O(1)

第三题是

A Zero-indexed array A consisting of N integers is given. We are looking for pairs of elements of the array that are equal but that occupy different positions in the array. More formally, a pair of indices (P, Q) is called identical if 0 ≤ P < Q < N and A[P] = A[Q]. The goal is to calculate the number of identical pairs of indices.
For example, consider array A such that A= [3,5,6,3,3,5]. In array A there are 4 pairs of identical indices (0,3) (0,4) (1,5) and (3,4). (2,2) and (5,1) are not counted since their fist indices are not smaller than their second.

评分

1

查看全部评分

aiweiwei 发表于 2016-3-12 23:13:51 | 显示全部楼层
楼主是不是第三题比较难?    第一题好像也没有太看懂。
回复 支持 反对

使用道具 举报

WLLiu 发表于 2016-3-15 07:12:01 | 显示全部楼层
第二题:
if A[0] == X
    A[0] = 1. 1point3acres.com/bbs
else
    A[0] = 0
// 计数,从[0,i]区间内有多少等于X的
// 耗时O(n)
for( i = 1; i < A.size; i++). Waral 鍗氬鏈夋洿澶氭枃绔,
    A[i] = A[i-1] + (A[i] == X).鏈枃鍘熷垱鑷1point3acres璁哄潧
// 全部是X,K等于0
if A[A.size-1] == A.size-google 1point3acres
    return 0
//检查一遍,耗时O(n)
for( K = 1; K < A.size; K++)
    // 前半等于X的元素个数 == 后不等于X的元素个数
    if  A[k-1] == S - K - (A[A.size-1] - A[K-1] )
        break
return K. 鐗涗汉浜戦泦,涓浜╀笁鍒嗗湴

回复 支持 反对

使用道具 举报

WLLiu 发表于 2016-3-15 07:18:22 | 显示全部楼层
第三题不太确信,是不是我想歪了?
input: A
output: sum
sum = 0
map<int,int> m
for each i in A:
    sum += m[i]
    m[i] ++
return sum
回复 支持 反对

使用道具 举报

本版积分规则

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

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

关闭

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

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

custom counter

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

Powered by Discuz! X3

© 2001-2013 Comsenz Inc. Design By HUXTeam

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