好未来教育产品研发人员面经及答案.docxVIP

  • 0
  • 0
  • 约5.25千字
  • 约 16页
  • 2026-03-09 发布于福建
  • 举报

好未来教育产品研发人员面经及答案.docx

第PAGE页共NUMPAGES页

2026年好未来教育产品研发人员面经及答案

一、编程能力测试(共5题,每题10分,总分50分)

1.题目(10分):

请实现一个函数,输入一个字符串,返回该字符串中所有唯一字符的列表(不区分大小写)。例如,输入`HelloWorld`,输出`[H,e,W,r,d]`。要求时间复杂度O(n)。

答案:

python

defunique_chars(s):

s_lower=s.lower()

seen=set()

unique=[]

forcharins_lower:

ifchar.isalpha()andcharnotinseen:

seen.add(char)

unique.append(char)

returnlist(unique)

示例

print(unique_chars(HelloWorld))#输出:[h,e,w,r,d]

解析:

-首先将字符串转为小写统一处理,避免大小写重复统计。

-使用`set`记录已见字符,确保唯一性。

-仅添加字母字符,符合题目要求。

-时间复杂度O(n),空间复杂度O(n)。

2.题目(10分):

请编写一个函数,输入一个列表`nums`,返回该列表中所有“连续递增”子数组的最大长度。例如,输入`[1,2,3,2,4,1,5]`,输出`5`(对应子数组`[2,4,1,5]`)。要求时间复杂度O(n)。

答案:

python

defmax_consecutive_increasing(nums):

ifnotnums:

return0

max_len=1

current_len=1

foriinrange(1,len(nums)):

ifnums[i]nums[i-1]:

current_len+=1

max_len=max(max_len,current_len)

else:

current_len=1

returnmax_len

示例

print(max_consecutive_increasing([1,2,3,2,4,1,5]))#输出:5

解析:

-使用滑动窗口思想,遍历列表时记录当前递增子数组的长度。

-每次发现递增则`current_len`加1,否则重置为1。

-用`max_len`记录最大长度,最终返回。

-时间复杂度O(n),空间复杂度O(1)。

3.题目(10分):

请实现一个二叉树的中序遍历非递归版本,返回遍历结果的列表。例如,输入以下二叉树:

1

/\

23

/\

45

输出`[4,2,5,1,3]`。

答案:

python

classTreeNode:

def__init__(self,val=0,left=None,right=None):

self.val=val

self.left=left

self.right=right

definorder_traversal(root):

stack,current=[],root

result=[]

whilestackorcurrent:

whilecurrent:

stack.append(current)

current=current.left

current=stack.pop()

result.append(current.val)

current=current.right

returnresult

示例树构建

root=TreeNode(1)

root.left=TreeNode(2,TreeNode(4),TreeNode(5))

root.right=TreeNode(3)

print(inorder_traversal(root))#输出:[4,2,5,1,3]

解析:

-使用栈模拟递归,先向左遍历,再处理节点并转向右子树。

-避免递归调用,空间复杂度O(h),时间复杂度O(n)。

4.题目(10分):

请编写一个函数,输入一个整数`n`,返回`1`到`n`的所有阶乘数的最后5位数字。例如,输入`10`,输出`[1,1,2,6,4,2,2,4,2,8]`(即`1!,2!,...,10!`的最后5位)。

答案:

python

deflast_five_factorials(n):

MOD=105

result=[1]

foriinrange(2,n+1):

result.append((result[-1]i)%

文档评论(0)

1亿VIP精品文档

相关文档