- 0
- 0
- 约7.73千字
- 约 19页
- 2026-02-01 发布于福建
- 举报
第PAGE页共NUMPAGES页
2026年数据面试题及抗压能力测试含答案
一、编程题(共5题,每题20分,总分100分)
1.数据结构与算法:设计一个高效的算法,找出数组中第三大的数。
要求:不使用排序,时间复杂度尽可能低。
python
defthird_largest(nums):
first,second,third=float(-inf),float(-inf),float(-inf)
fornuminnums:
ifnumfirst:
third,second,first=second,first,num
eliffirstnumsecond:
third,second=second,num
elifsecondnumthird:
third=num
returnthirdifthird!=float(-inf)elseNone
2.数据结构与算法:实现一个LRU(最近最少使用)缓存,支持get和put操作。
要求:使用哈希表和双向链表实现,时间复杂度为O(1)。
python
classListNode:
def__init__(self,key=None,value=None):
self.key=key
self.value=value
self.prev=None
self.next=None
classLRUCache:
def__init__(self,capacity:int):
self.capacity=capacity
self.cache={}
self.head,self.tail=ListNode(),ListNode()
self.head.next=self.tail
self.tail.prev=self.head
defget(self,key:int)-int:
ifkeyinself.cache:
node=self.cache[key]
self._move_to_head(node)
returnnode.value
return-1
defput(self,key:int,value:int)-None:
ifkeyinself.cache:
node=self.cache[key]
node.value=value
self._move_to_head(node)
else:
node=ListNode(key,value)
self.cache[key]=node
self._add_node(node)
iflen(self.cache)self.capacity:
node=self._pop_tail()
delself.cache[node.key]
def_move_to_head(self,node):
self._remove_node(node)
self._add_node(node)
def_add_node(self,node):
node.prev=self.head
node.next=self.head.next
self.head.next.prev=node
self.head.next=node
def_remove_node(self,node):
prev_node=node.prev
next_node=node.next
prev_node.next=next_node
next_node.prev=prev_node
def_pop_tail(self):
res=self.tail.prev
self._remove_node(res)
returnres
3.数据结构与算法:实现一个简单的Trie(前缀树),支持插入和查询操作。
要求:支持插入字符串和查询字符串是否存在。
python
classTrieNode:
def__init__(self):
self.children={}
self.is_end=False
classTrie:
def__init__(self):
self.root=TrieNode()
definsert(self,word:str)-None:
node=self.root
forcharinword:
ifcharnotinnode.children:
node.children[char]=TrieNode()
node=node.child
您可能关注的文档
- 2026年粉丝运营面试题及答案.docx
- 智能硬件研发面试题及电路基础含答案.docx
- 2026年干部考察面试题集.docx
- 股权结构分析与理解测试题.docx
- 2026年翻译质量考核标准及流程.docx
- 2026年程序员职场成长攻略与面试题.docx
- 上药集团法务专员面试题及解析.docx
- 网络安全领域的产品设计专员全题型题库与解析.docx
- 2026年教育行业校长面试题及答案解析.docx
- 物流企业成本控制面试题详解.docx
- 人教版九年级英语Unit 4曾害怕课件3a-4c.pdf
- 雅思口语考题回顾:朗阁海外考试研究中心2019年10月10日Part 1考题总结.pdf
- 2026届高三地理一轮复习课件小专题河流袭夺.pptx
- 【名师原创】复习专题5 三角函数 作者:合肥市第八中学 蒲荣飞名师工作室.docx
- 高中数学一轮复习 微专题2 抽象函数.docx
- 高中数学——复习专题4 空间向量与立体几何.docx
- 高中数学一轮复习 微专题3 空间几何体中的截面、轨迹问题.docx
- 高中数学一轮复习 微专题4 空间几何体的最值、范围问题.docx
- 导流洞施工质量通病防治手册.docx
- 江苏省徐州市第一中学、徐市第三中学等五校2026届高三上学期12月月考历史试题含答案.docx
原创力文档

文档评论(0)