ARST打卡第197周[197/521]

Algorithm

lc84_柱状图中最大的矩形

单调栈处理连续的面积问题

84题题解

单调栈优化版,有点难理解的,不过对单调栈的巩固复习是很有帮助的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
func largestRectangleArea(heights []int) int {
n := len(heights)
left, right := make([]int, n), make([]int, n)
for i := 0; i < n; i++ {
right[i] = n
}
mono_stack := []int{}
for i := 0; i < n; i++ {
for len(mono_stack) > 0 && heights[mono_stack[len(mono_stack)-1]] >= heights[i] {
right[mono_stack[len(mono_stack)-1]] = i
mono_stack = mono_stack[:len(mono_stack)-1]
}
if len(mono_stack) == 0 {
left[i] = -1
} else {
left[i] = mono_stack[len(mono_stack)-1]
}
mono_stack = append(mono_stack, i)
}
ans := 0
for i := 0; i < n; i++ {
ans = max(ans, (right[i] - left[i] - 1) * heights[i])
}
return ans
}

func max(x, y int) int {
if x > y {
return x
}
return y
}

不过需要注意的一个点就是,不要因为做多了单调栈就不记得做简单题了

比如lc11_盛最多水的容器就不是连续的柱子高度,而是中间加水,所以可以用简单的双指针

两边l,r指针,把短的height[l] 或者 height[r]向内部移动,维护最大面积就是答案[捂脸],一开始想复杂了,以为是柱子求矩形面积的那种题目

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Solution {
public:
int maxArea(vector<int>& height)
{
int maxarea = 0,l = 0, r = int(height.size()) - 1;
while (l < r) {
maxarea = max(maxarea, min(height[l], height[r]) * (r - l));
if (height[l] < height[r])
l++;
else
r--;
}
return maxarea;
}
};

Review

Interview: A day in the life of a programmer

I think a successful programmer is someone who can adapt rapidly to change, as technology tends to move very fast, and you can find yourself needing to quickly get the hang of new frameworks and libraries. Soft skills are sometimes underestimated, but good communication and a collaborative spirit are really important factors. The need for these soft skills is perennial, whereas technical knowledge of a particular language or framework can quickly become obsolete.

Tips

CubeFS进入CNCF孵化阶段,国产分布式存储的新里程碑

Share

Api7.ai面试分享-2022.2.11下午4点

面试官是api7.ai的CTO王院生,然后比我还早进入会议室,有点震惊

整体询问的是英语水平,开源项目贡献程度,技术栈贴合程度

最终从面试沟通中学习到以下几个技术人生建议

  1. 不要只低头做事,学会抬头看路,参与到所在领域的最大的开源项目中去
  2. 不要只是口头上说开源好,要实际参与到开源项目中去

忠言逆耳利于行,感谢前辈老师的直接指出核心问题

以后自己也要多抬头看路,参与到真正的开源贡献,这才是最美的简历