在恒定空间中交织数组 [英] Interleave array in constant space

查看:72
本文介绍了在恒定空间中交织数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了以下示例求职面试问题.我该怎么解决?

假设我们有一个数组 a1,a2,...,an,b1,b2,...,bn.

目标是将此数组更改为 在O(n)时间和O(1)空间中a1,b1,a2,b2,...,an,bn. 换句话说,我们需要一种线性时间算法来修改阵列,而最多只能有恒定数量的额外存储空间.

解决方案

这个问题并不像人们想象的那么简单.在家工作?大声笑.

以下链接提供了解决方案: http://arxiv.org/abs/0805.1598

I ran across the following sample job interview question. How can I solve it?

Suppose we have an array a1, a2,... , an, b1, b2, ..., bn.

The goal is to change this array to a1, b1, a2, b2, ..., an, bn in O(n) time and in O(1) space. In other words, we need a linear-time algorithm to modify the array in place, with no more than a constant amount of extra storage.

解决方案

This problem is not as trivial as people make out to be. Homework? LOL.

The following link has a solution: http://arxiv.org/abs/0805.1598

这篇关于在恒定空间中交织数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆