IBM面试攻略:真题解答与OA面经
IBM 的招聘流程通常始于初步的简历筛选,旨在评估申请人的背景和与职位相符的技术专长。通过简历筛选的候选人,往往需要完成在线编程测试(Online Assessment, OA),这主要考察编码和解决问题的能力,是进入后续阶段的重要门槛。
成功通过 OA 后,候选人会进入一到两轮电话面试。这些电话面试侧重于技术能力的考察,同时也会包含一些行为问题,以评估候选人与 IBM 企业文化的契合度。通过电话面试的申请人将进入最终的现场面试(Onsite Interviews)。
IBM 的现场面试通常包含三到四轮,内容涵盖技术和行为方面。面试环节结构多样,可能包括编程挑战、系统设计问题以及行为面试,旨在全面评估候选人的问题解决能力、编码技巧以及与 IBM 价值观的契合度。整个面试过程的难度通常在中等到具有挑战性之间,具体取决于职位的要求。
内容列表
IBM OA通常会提问2个较为简单的coding问题,但时间上较为紧凑,以下是CSOAsupport面试辅助团队在面试期间花20分钟帮候选人A答题的实际案例。
OA 面试题1
你是一名云服务公司的 DevOps 工程师,负责管理着大量的服务器。你手头有 n 种不同类型的任务,每种任务都有固定的处理时间。其中,第 i 种任务需要 i 分钟来完成。
目前,系统里已经有 m 个任务正在运行,它们各自的处理时间列在一个名为 arr 的数组中。你的团队还有 k 分钟的空闲计算资源,你需要利用这些时间来尽可能多地处理新的任务。
核心问题是:在不中断任何现有任务的前提下,你最多能完成多少个不同的新任务?
解决方案思路
这个问题的核心原则与之前的类似:给定一个有限的资源(这里是 k 分钟的空闲时间),如何才能最大化我们能完成的任务数量?由于每种任务都有固定的处理时间,最聪明的做法就是采用 贪心策略——总是优先处理耗时最短的任务。这样一来,你就能在有限的时间内塞下最多的任务。- 确定可用任务:首先,我们需要找出所有可以“抢占”的可用任务。任务类型总共有 n 种,编号从 1 到 n,对应的处理时间也从 1 到 n 分钟。我们将简单地排除掉那些已经在运行的 m 个任务(它们在 arr 数组中)。
- 按处理时间排序:幸运的是,剩下的可用任务已经按照处理时间自动排好了顺序(1, 2, 3…)。这意味着我们可以直接从耗时最短的任务开始。
- 分配资源:我们从耗时最短的任务开始。如果我们的空闲时间(k)足够,就“处理”这个任务,然后从预算中减去它所用的时间,接着处理下一个耗时更短的任务。我们会一直重复这个过程,直到资源耗尽或者我们无法再承担任何一个新任务。
- 计算总数:最后,将我们新完成的任务数量,加上原本就在运行的 m 个任务,就是我们总共处理的不同任务数量。
def max_tasks(n, arr, k):
"""
Calculates the maximum number of different tasks that can be completed
with the given resources.
Args:
n: The total number of task types, numbered 1 to n.
arr: An array representing the m tasks that are already running.
k: The total available computing resources (in minutes).
Returns:
int: The maximum total number of different tasks that can be handled.
"""
# 1. Figure out which tasks are not yet running
running_tasks = set(arr)
available_tasks = []
for i in range(1, n + 1):
if i not in running_tasks:
available_tasks.append(i)
# 2. Greedy approach: process the quickest tasks first
newly_completed_tasks = 0
for task_time in available_tasks:
if k >= task_time:
k -= task_time
newly_completed_tasks += 1
else:
# Not enough resources, so we have to stop here
break
# 3. Add the newly completed tasks to the ones already running
total_tasks = len(arr) + newly_completed_tasks
return total_tasks
# Example:
# Let's say we have n=10 tasks, m=3 tasks already running (with IDs 2, 5, 8),
# and k=15 minutes of free resources.
n_example = 10
arr_example = [2, 5, 8]
k_example = 15
result = max_tasks(n_example, arr_example, k_example)
print(f"The maximum total number of different tasks we can handle is: {result}") # Output: 7
# Breakdown:
# The tasks that are available are 1, 3, 4, 6, 7, 9, 10.
# Greedy picks:
# - Process task 1 (costs 1), k becomes 14.
# - Process task 3 (costs 3), k becomes 11.
# - Process task 4 (costs 4), k becomes 7.
# - Process task 6 (costs 6), k becomes 1.
# - Task 7 costs 7, which is more than k's remaining value, so we stop.
# We completed 4 new tasks. Total tasks = 3 already running + 4 new ones = 7.
OA 面试题2
为提升执行速度,现代 CPU 使用指令缓存来存储最近使用的指令。当 CPU 需要执行一条指令时,它会首先检查缓存。如果指令在缓存中(缓存命中,cache hit),CPU 就能快速执行;如果不在(缓存未命中,cache miss),CPU 就必须从主内存中获取,这会耗费大量时间。
本次任务的目标是模拟一个先进先出(FIFO)的指令缓存,并计算执行一系列指令所需要的总时间。
解决方案思路
我们将采用先进先出(FIFO)的缓存策略来管理缓存。当缓存已满,需要加载新指令时,在缓存中停留时间最久(即“先进先出”)的指令将被移除,为新指令腾出空间。解题步骤
- 初始化缓存:使用一个队列(例如 Python 的 collections.deque)来存储缓存中的指令。队列“先进先出”的特性完美契合 FIFO 策略。
- 处理每条指令:遍历指令列表中的每一条指令。
- 如果指令已在缓存中(缓存命中),执行时间为 cache_time。
- 如果指令不在缓存中(缓存未命中),执行时间为 memory_time。
- 如果缓存已满,移除队列头部的指令(即最旧的指令)。
- 将新指令添加到队列尾部。
- 计算总时间:将每条指令的执行时间相加,得到总耗时。
import collections
def simulate_fifo_cache(instructions, cache_size, cache_time, memory_time):
"""
Simulates a FIFO (First-In, First-Out) instruction cache and calculates the total execution time.
:param instructions: A list of all instructions to be processed.
:param cache_size: The maximum capacity of the cache.
:param cache_time: The execution time for a cache hit.
:param memory_time: The execution time for a cache miss.
:return: The total time required to execute all instructions.
"""
cache = collections.deque(maxlen=cache_size)
total_time = 0
for instruction in instructions:
if instruction in cache:
# Cache Hit
total_time += cache_time
else:
# Cache Miss
total_time += memory_time
if cache_size > 0: # Ensure cache size is greater than 0
# The deque automatically handles removing the oldest element when full.
cache.append(instruction)
return total_time
# Example usage
instructions_list = ['add', 'sub', 'mul', 'add', 'div', 'sub', 'add', 'mov']
cache_capacity = 3
cache_access_time = 1 # Cache access time is 1 unit
memory_access_time = 10 # Main memory access time is 10 units
total_execution_time = simulate_fifo_cache(instructions_list, cache_capacity, cache_access_time, memory_access_time)
print(f"Instruction List: {instructions_list}")
print(f"Cache Capacity: {cache_capacity}")
print(f"Total Execution Time: {total_execution_time} units")
面試準備
面试前的准备期要给自己设定每日刷题计划,尤其是在LeetCode、HackerRank等平台上刷题,重点练习带有IBM标签的的数据结构和算法题,其次是可以请教reddit社区下的子话题社区“LeetCode”,咨询一些有过对应面试经验的社区伙伴,争取获得一手的面试信息以及模拟面试机会,如果您的时间进度来不及自己刷题,且条件允许的情况下可以考虑采用CSOAsupport的IBM OA面试辅助和代面服务,让您的努力事半功倍!