Posts

Showing posts from October, 2026

Sliding Window Technique - Part 14

Image
A bit of vintage coding, no GAI involved. This is a sliding window problem, it is a bit tricky because you have to maintain not only the numbers in the candidate subarray but also the sum of pairs in that subarray, so two different data structures (I used hash tables but you can use other dictionary data structures) to keep this information. You need to update both of them accordingly when moving either the right pointer or the left one. Complexity is N^2 (N==1000) however the usage of untyped hash tables is slowing down the constant significantly, there are other ways especially given that the numbers in the array are small-bounded. Code is down below, cheers, ACC. Longest Subarray With Restricted Pair Sums - LeetCode You are given an integer array nums . A subarray nums[l..r] is valid if there are no three distinct indices i , j , and k such that l <= i, j, k <= r and: nums[i] + nums[j] == nums[k] Return the maximum length of a valid subarray of nums .   Example 1: In...