OCI 面试经验分享 | 职业规划, 工作申请, 面试准备
OCI 面试经验分享 | 职业规划, 工作申请, 面试准备
在最近的OCI面试中,面试官考察了多个方面的编程技能,从数组操作到日期处理,题目涵盖广泛。这类面试强调了快速思考和精准编程的重要性。我们提供的职业规划和工作申请服务能够帮助你准备这些类型的面试问题,提高你的编程技能,让你在面试中脱颖而出。
如果你想要更好地应对这样的技术面试,欢迎添加微信 leetcode-king,了解更多关于我们的服务信息。
题目1:Binary Search Occurrences
Problem Description:
Given a sorted array of integers, find the number of occurrences of a given target value.
Code:
def find_occurrences(nums, target):
def find_first_occurrence(nums, target):
left, right = 0, len(nums) - 1
first_occurrence = -1
while left <= right:
mid = left + (right - left) // 2
if nums[mid] == target:
first_occurrence = mid
right = mid - 1
elif nums[mid] < target:
left = mid + 1
else:
right = mid - 1
return first_occurrence
def find_last_occurrence(nums, target):
left, right = 0, len(nums) - 1
last_occurrence = -1
while left <= right:
mid = left + (right - left) // 2
if nums[mid] == target:
last_occurrence = mid
left = mid + 1
elif nums[mid] < target:
left = mid + 1
else:
right = mid - 1
return last_occurrence
first = find_first_occurrence(nums, target)
last = find_last_occurrence(nums, target)
return (last - first + 1) if first != -1 else 0
print(find_occurrences([1, 2, 2, 2, 3, 4], 2)) # Output: 3
题目2:Maximize PTO Days
Problem Description:
You're given a calendar year represented as an array that contains either 'H' (holiday) or 'W' (workday). Given a number of personal time-off (PTO) days, maximize the length of the longest vacation you can take. No rollovers allowed.
Code:
def maximize_pto_days(year, pto):
max_vacation = 0
left = 0
right = 0
current_pto = 0
while right < len(year):
if year[right] == 'W':
if current_pto < pto:
current_pto += 1
else:
while year[left] != 'W':
left += 1
left += 1
right += 1
max_vacation = max(max_vacation, right - left)
return max_vacation
year = ['W', 'H', 'H', 'W', 'W', 'H', 'W']
pto = 2
print(maximize_pto_days(year, pto)) # Output: 5