当前位置:网站首页>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
边栏推荐
- Spark 离线开发框架设计与实现
- The efficient s2b2c e-commerce system helps electronic material enterprises improve their adaptability in this way
- In the field of software engineering, we have been doing scientific research for ten years!
- JS get the key and value of the object
- 成年人只有一份主业是要付出代价的,被人事劝退后,我哭了一整晚
- Inftnews | the wide application of NFT technology and its existing problems
- 2022注册测绘师备考开始 还在不知所措?手把手教你怎么考?
- 高级程序员必知必会,一文详解MySQL主从同步原理,推荐收藏
- UE4_UE5结合罗技手柄(F710)使用记录
- Talk about the design and implementation logic of payment process
猜你喜欢
Mysql索引优化实战一
2022注册测绘师备考开始 还在不知所措?手把手教你怎么考?
Home appliance industry channel business collaboration system solution: help home appliance enterprises quickly realize the Internet of channels
S2b2b mall solution of intelligent supply chain in packaging industry: opening up a new ecosystem of e-commerce consumption
RE1 attack and defense world reverse
LDO稳压芯片-内部框图及选型参数
B_ QuRT_ User_ Guide(36)
SRM supplier cloud collaborative management platform solution for building materials industry to realize business application scalability and configuration
包装行业智能供应链S2B2B商城解决方案:开辟电商消费新生态
MySQL Index Optimization Practice II
随机推荐
PHP uses Alibaba cloud storage
How can we make money by making video clips from our media?
海内外技术人们“看”音视频技术的未来
Oracle database backup and recovery
B_QuRT_User_Guide(36)
MATLAB signal processing [Q & A essays · 2]
13、 System optimization
家用电器行业渠道商协同系统解决方案:助力家电企业快速实现渠道互联网化
LDO穩壓芯片-內部框圖及選型參數
移动端异构运算技术 - GPU OpenCL 编程(基础篇)
As a new force, chenglian premium products was initially injected, and the shares of relevant listed companies rose 150% in response
进度播报|广州地铁七号线全线29台盾构机全部完成始发
POJ2392 SpaceElevator [DP]
PCB wiring rules of PCI Express interface
LM12丨Rolling Heikin Ashi二重K线滤波器
系统架构设计师备考经验分享:论文出题方向
B / Qurt Utilisateur Guide (36)
2021ICPC上海 H.Life is a Game Kruskal重构树
php 使用阿里云存储
高效的S2B2C电商系统,是这样帮助电子材料企业提升应变能力的