当前位置:网站首页>8.31 Tencent interview
8.31 Tencent interview
2022-07-07 23:28:00 【codepig16】
8.31 Tencent interview
Two arithmetic questions
Enter a set of numbers , Output the second largest number . Avoid using the sorting function that comes with the language
requirement : Use one-time traversal to realize
Thought analysis
Find the first k Big element , We need to learn to maintain a small top stack to achieve , If the element is larger than the top of the heap, put it in the heap , Here is the second element, which is relatively simple .
Code implementation
public int getSecond(int[] nums) {
//a Is the maximum value. b Is the second largest value
int a = Integer.MIN_VALUE, b = Integer.MIN_VALUE;
for (int i = 0; i < nums.length; i++) {
if (nums[i] > a) {
b = a; a = nums[i];}
else if (nums[i] > b) b = nums[i];
}
return b;
}
Enter two integers n and m, From the sequence 1,2,3…….n Take a few numbers at random , Make the sum equal to m , Ask for a list of all possible combinations , Arrange from small to large
Thought analysis
List<List<Integer>> res = new ArrayList<>();
List<Integer> list = new ArrayList<>();
// From index To n Middle sum is m Result
public void dfs(int index, int m, int n) {
if (m == 0) {
res.add(new ArrayList<>(list));
} else {
for (int i = index; i <= m && i <= n; i++) {
list.add(i);
dfs(i + 1, m - i, n);
list.remove(list.size() - 1);
}
}
}
The type of the second question can be changed into , Get the number of conditions from the array , Similar topics are
边栏推荐
- POJ2392 SpaceElevator [DP]
- PCB wiring rules of PCI Express interface
- 成年人只有一份主业是要付出代价的,被人事劝退后,我哭了一整晚
- Technology at home and abroad people "see" the future of audio and video technology
- 电子设备行业智能供应链协同平台解决方案:解决低效, 赋能产业数字化升级
- 云原生正在吞噬一切,开发者该如何应对?
- Unity3D学习笔记4——创建Mesh高级接口
- 高效的S2B2C电商系统,是这样帮助电子材料企业提升应变能力的
- The 19th Zhejiang Provincial Collegiate Programming Contest VP记录+补题
- 2022 Season 6 perfect children's model Shaanxi finals came to a successful conclusion
猜你喜欢

UE4_UE5结合罗技手柄(F710)使用记录

S2b2b mall solution of intelligent supply chain in packaging industry: opening up a new ecosystem of e-commerce consumption
![MATLAB signal processing [Q & A essays · 2]](/img/be/0baa92767c3abbda9b0bff47cb3a75.png)
MATLAB signal processing [Q & A essays · 2]

LeeCode -- 6. Z 字形变换

建筑建材行业SRM供应商云协同管理平台解决方案,实现业务应用可扩展可配置

【编译原理】词法分析设计实现

移动端异构运算技术 - GPU OpenCL 编程(基础篇)

Explain

First week of July

Unity3D学习笔记5——创建子Mesh
随机推荐
As a new force, chenglian premium products was initially injected, and the shares of relevant listed companies rose 150% in response
re1攻防世界逆向
Technology at home and abroad people "see" the future of audio and video technology
云原生正在吞噬一切,开发者该如何应对?
B_QuRT_User_Guide(36)
Ros2 topic (03): the difference between ros1 and ros2 [02]
The 19th Zhejiang Provincial College Programming Contest 2022 f.easyfix chairman tree
USB (XVI) 2022-04-28
System design overview
USB (十八)2022-04-17
Sequence of entity layer, Dao layer, service layer and controller layer
B_ QuRT_ User_ Guide(40)
SRM supplier cloud collaborative management platform solution for building materials industry to realize business application scalability and configuration
Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting
Solution of intelligent supply chain collaboration platform in electronic equipment industry: solve inefficiency and enable digital upgrading of industry
Unity3D学习笔记5——创建子Mesh
2022 Season 6 perfect children's model Shaanxi finals came to a successful conclusion
HDU 4747 mex "recommended collection"
Digital procurement management system for fresh food industry: help fresh food enterprises solve procurement problems and implement online procurement throughout the process
USB(十六)2022-04-28