Mercurial
view asyncio_threads/frontend/longest_subinteger.py @ 279:b3b547563ec7
Add Google connector service and agent wiki
Implement the C/Seobeo Google Drive and Gmail connector with encrypted OAuth storage, Zenbu authentication, browser testing, AI tool discovery, chunked HTTP decoding, and Bazel coverage. Consolidate repository guidance into progressive wiki documentation and enforce arena-first allocation for new first-party C code.
Co-authored-by: Copilot <[email protected]>
Copilot-Session: 84c338fd-0939-4bb3-b7f3-1062eb213e5d
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Mon, 17 Aug 2026 22:22:36 -0700 |
| parents | 46daba6e3cf4 |
| children |
line wrap: on
line source
# Analyze a given array of integers and write a function to determine the length of the longest subsequent growing sequence contained within the array. # 1,2,3,4,2,1,3 # | # Example 1: # # Input: nums = [10,9,2,5,3,7,101,18] # [(2, 1), 3, 5, 7, 9, 10, 18, 101] # | # Output: 4 # Explanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4. # Example 2: # # Input: nums = [0,1,0,3,2,3] # Output: 4 # Example 3: # # Input: nums = [7,7,7,7,7,7,7] # Output: 1 # Longest Increasing Subsequence def main(nums): ans = 0 cache = set() def dfs(val, pos, curr_ans): nonlocal ans if ((val, pos, curr_ans) in cache): return if pos > len(nums): return if nums[pos] > val: curr_ans += 1 else: ans = max(ans, curr_ans) return for i in range(pos, len(nums)): dfs(nums[pos], i, curr_ans) for i in range(len(nums)): dfs(float("-inf"), i, 0) return ans print(main([10,9,2,5,3,7,101,18]))