单调栈
Search documents
实习生摸鱼被大厂开了。。
猿大侠· 2025-12-22 04:11
以下文章来源于数据结构和算法 ,作者博哥 数据结构和算法 . 《算法秘籍》作者王一博,专注于互联网大厂热点事件和算法题讲解。 最近一网友在网上发文称自己实习,由于摸鱼被大厂开除了, 因为蹲了个厕所,回来刷了会手 机,被老板发现,让他别玩手机,结果过了四十分钟,HR让他重现找工作了。 就因为一次摸鱼被开除,这只是公司开除的一个借口而已,就是不想让你转正。并且该实习生也说 了,四个实习生只能有一个转正。所以你摸不摸鱼都一样会被开除。 大厂实习竞争激烈能理解, 不过也不用太纠结,这种不尊重员工、做事如此生硬的公司,就算转 正留下,后续工作体验大概率也不会好。 --------------下面是今天的算法题-------------- 来看下今天的算法题,这题是LeetCode的第 496题:下一个更大元素 I,难度是简单。 nums1 中数字 x 的下一个更大元素是指 x 在 nums2 中对应位置右侧的第一个比 x 大的元素。 给你两个没有重复元素的数组 nums1 和 nums2 ,下标从 0 开始计数,其中 nums1 是 nums2 的 子集 。 对于每个 0 <= i < nums1.length ,找出 ...
为了不让实习生下班走,故意每晚9:30开会
猿大侠· 2025-10-01 04:11
Core Viewpoint - The article discusses a specific algorithm problem from LeetCode, focusing on the "132 pattern" in an integer array, and provides a detailed explanation of how to solve it using a monotonic stack approach [4][9]. Summary by Sections Algorithm Problem Description - The problem is to determine if there exists a subsequence in the array that follows the "132 pattern," where for three integers nums[i], nums[j], and nums[k], the conditions i < j < k and nums[i] < nums[k] < nums[j] must hold true [5][9]. Examples - Example 1: For the input nums = [1,2,3,4], the output is false, indicating no "132 pattern" exists [6]. - Example 2: For the input nums = [3,1,4,2], the output is true, as the subsequence [1, 4, 2] satisfies the "132 pattern" [8]. Problem Analysis - The solution involves using a monotonic stack to efficiently find the "132 pattern." An auxiliary array, leftMin, is used to track the minimum values to the left of each element [9][10]. Implementation Details - The algorithm iterates from the end of the array to the beginning, checking for the "3" in the "132 pattern" and using the stack to find the corresponding "2" and "1" [10][12]. - The Java and C++ implementations of the algorithm are provided, demonstrating how to set up the leftMin array and the stack operations [10][13].