613 questions
0
votes
1
answer
66
views
How to configure roll function for sliding window on irregular stock data?
I am working with irregular minute-level stock data in DolphinDB and need to implement a specific rolling calculation using the roll function which is new in version 3.00.4.
I have a custom ...
1
vote
1
answer
112
views
Why is my sliding window algorithm not showing results?
The current problem I'm having is that when the code runs it shows me "None" in the terminal.
/usr/local/bin/python3.12/Users/jaredmccarthy/Desktop/2025/ejercicios_leetcode.py
None
Process ...
1
vote
0
answers
54
views
How to create a sliding window for 30 mins to calculate total number of events happened in that time frame in BigQuery
I need to create an incremental window of 30 mins to show total number of events in that time frame in BigQuery. I am sharing a sample table and the desired output for the reference.
The original ...
5
votes
4
answers
203
views
How to use the apply function to return a list to new column in Pandas
I have a Pandas dataframe:
import pandas as pd
import numpy as np
np.random.seed(150)
df = pd.DataFrame(np.random.randint(0, 10, size=(10, 2)), columns=['A', 'B'])
I want to add a new column "C&...
0
votes
1
answer
33
views
How to distinguish elements from offset time in sliding window?
I am wondering whether it is possible to distinguish elements from offset time in Apache Flink sliding windows. Let me explain it in more details.
I want to take elements from eg.: 13:00 to 13:59:59. ...
0
votes
1
answer
72
views
check if there is a subarray of length l or smaller with a sum greater than or equal to k
I was trying to solve Leetcode 862. Shortest Subarray with Sum at Least K. My approach was to binary search on a sliding window. So I needed a method which checks for a given length sol, if there ...
-1
votes
3
answers
133
views
How can I efficiently find if an array contains duplicates within a specific distance using Python? [closed]
I'm working on a Python problem where I need to check if an unsorted array contains any duplicates within a specified distance k. Specifically, I need to return True if any value appears more than ...
-5
votes
1
answer
708
views
Finding longest substring without repeating characters [closed]
I'm trying to solve LeetCode 3: Longest Substring Without Repeating Characters.
I'm implementing the Sliding Window method, which consists of using a left and a right pointer to contract and expand ...
0
votes
0
answers
104
views
How to prove the sliding window algorithm works to find the largest non repeating substring
Doing the leetcode problem https://leetcode.com/problems/longest-substring-without-repeating-characters/ I found this solution:
def lengthOfLongestSubstring(self, s: str) -> int:
left = 0
...
8
votes
3
answers
1k
views
How do I do calculations with a sliding window while being memory-efficient?
I am working with very large (several GB) 2-dimensional square NumPy arrays. Given an input array a, for each element, I would like to find the direction of its largest adjacent neighbor. I am using ...
-1
votes
2
answers
743
views
Flip consecutive zeroes to ones in k operations to have maximum number of ones, find the maximum number of ones
You are given a binary string made of 0 and 1, and a value k which represents number of operations. You can flip consecutive 0s in each operation to 1s. Find the maximum number of 1s after k ...
2
votes
1
answer
98
views
Longest Repeating Substring With Replacement
Working on an online practice problem and ran into an issue that I can't seem to figure out. I am looking to find the longest length of a string of characters whose characters can only be replaced &...
1
vote
1
answer
141
views
Why does the sliding window algorithm not work for this problem statement?
The question is regarding an algorithm which I'm using to solve a problem. The problem statement is: (or view it here)
"Given arrival and departure times of all trains that reach a railway ...
-1
votes
2
answers
2k
views
Length of Longest Subarray With A Consistent Frequency
Given an array A, a subarray of A is called "consistent" if the maximum occurrence of all elements in the subarray is equal to the minimum occurrence of all elements in the subarray. Find ...
1
vote
4
answers
142
views
The minimum size of substrings for the presence of at least one character
i have a question that want the minimum length of k that in each consecutive substring of a string with length k, There must be at least one common character.
for example if s="abcaca"
for k ...
0
votes
0
answers
30
views
Difference in desktop site & mobile site's view of sliding gallery
I've been trying to get this thing to work for a while now, but it's been giving me headaches.
(Not an experienced coder here), But i was able to add a sliding gallery to my site : https://www....
0
votes
0
answers
74
views
Cold data migration with sliding window stored procedure for partitioned tables in SQL Server
I am trying to write a sliding window stored procedure in SQL Server in order to migrate cold data to a cold storage. To do this, I planned on creating an "Archiving" table, that will store ...
1
vote
1
answer
137
views
Calculating percentile over a sliding window in Power Query
I have a table with 5 columns, District (type text), Month Cumulative (Int64.Type), Measurement (type text), Value (type number) and Monthdate (type Date, 1/mm/yyyy). The table is sorted on District ...
0
votes
4
answers
199
views
Find substrings that contain a certain amount of certain characters
I have a string like GGACATCGCGGTGGATCGAC.
How can I find all substrings that contain, for example, three Gs in any order?
For this string, it would be GCGG or GTGG, or GGACATCG.
Also need to find ...
1
vote
1
answer
197
views
Time Complexity of Inner Loop of sliding window algorithm
I am looking at a LeetCode problem 1838. Frequency of the Most Frequent Element:
The frequency of an element is the number of times it occurs in an array.
You are given an integer array nums and an ...
0
votes
0
answers
56
views
Count With K Different Characters
The problem is basically to count the number of substrings with exactly k distinct characters.There can be duplicate as long as there are k distinct characters.
I was trying sliding window method in ...
0
votes
1
answer
153
views
Check if this code uses a data sliding window
I want help to check if the following code (from https://github.com/jsh4887/ConvLSTM/blob/main/1.%20Make_dataset.py):
import os
import numpy as np
import pandas as pd
import pickle
from sklearn....
0
votes
2
answers
480
views
Sliding window Minimum Size Subarray Sum
Given an array of positive integers nums and a positive integer target, return the minimal length of a
subarray
whose sum is greater than or equal to target. If there is no such subarray, return 0 ...
1
vote
2
answers
630
views
Count Subarrays Where Max Element Appears at Least K Times sliding window
Problem
Count Subarrays Where Max Element Appears at Least K Times
You are given an integer array nums and a positive integer k. Return the number of subarrays where the maximum element of nums ...
0
votes
1
answer
150
views
Minimum window substring not sliding correctly
Problem
Minimum Window Substring
Given two strings s and t of lengths m and n respectively, return the minimum window
substring
of s such that every character in t (including duplicates) is included ...
0
votes
1
answer
1k
views
Apply Operations to Make All Array Elements Equal to Zero
So I attempted this leetcode problem and I was able to come up with a solution that passes 1017/1026 test cases. The remaining that failed did so due to the time limit exceeding and not incorrectness ...
0
votes
1
answer
80
views
what's the time complexity of this code with sliding window?
parent for loop has On , while loop has amoritised O n? meaning we consider it O 1? also
min and max operations they will be O k but again On in worst case?
is it O (n^3) ?
left=0
...
2
votes
1
answer
89
views
Sliding subarray beauty working on IDE but not on leetcode
Problem
2653. Sliding Subarray Beauty
Given an integer array nums containing n integers, find the beauty of
each subarray of size k.
The beauty of a subarray is the xth smallest integer in the ...
1
vote
1
answer
111
views
why it is not possible use matplotlib.animation when data type within pandas dataframe is datetime due to your time stamp?
I'm experimenting with 1D time-series data and trying to reproduce the following approach via animation over my own data in GoogleColab notebook.
I faced the problem of re-producing animation from ...
0
votes
1
answer
77
views
Sliding Window Maximum wrong answer
Problem
You are given an array of integers nums, there is a sliding window
of size k which is moving from the very left of the array to the
very right. You can only see the k numbers in the window. ...
-1
votes
2
answers
149
views
Time limit exceeded on the code: Check If a String Contains All Binary Codes of Size K
I'm trying to solve LeetCode problem 1461. Check If a String Contains All Binary Codes of Size K:
Given a binary string s and an integer k, return true if every binary code of length k is a substring ...
0
votes
1
answer
97
views
Adjust max distance for stumpy match function
I use python stumpy to extract subsequences from a timeseries. For a pattern Q and a timeseries T, I use the function stumpy.match https://stumpy.readthedocs.io/en/latest/api.html#stumpy.match
Now ...
0
votes
1
answer
122
views
Edge case of binary subarray with sum
Problem
Given a binary array nums and an integer goal, return the number of non-empty subarrays with a sum goal.
Link to the problem
Code
class Solution:
def numSubarraysWithSum(self, nums, goal):
...
0
votes
1
answer
102
views
Maximum sum of distinct subarrays with k stuck at flag logic
Problem
You've given an integer array nums and integer k. Find the maximum subarray sum of all the subarraay of nums that meet the following conditions.
The length of the subarray is k, and
All the ...
1
vote
1
answer
192
views
what is going wrong in Minimum size subarray sum end condition
Problem
Given an array of positive integers nums and a positive integer target, return minimal length of subarray whose
sum is greater than or equal to target. If there is no such subarray, return 0 ...
1
vote
1
answer
149
views
What is going wrong in this longest subarray of 1s after deleting one element
I'm trying to solve LeetCode problem 1493. Longest Subarray of 1's After Deleting One Element:
Given a binary array nums, you should delete one element from it.
Return the size of the longest non-...
0
votes
2
answers
457
views
Find max frequency in each k sized subarray
Can be repetitive, but I couldn't find exact one.
This is the part of a problem involving Data Structure and Algotrithms:
Given an array of size n, find max frequency among the all elements in the ...
-3
votes
1
answer
119
views
iOS Swift - Leetcode 1567. Maximum Length of Subarray With Positive Product
I'm looking at the below solution, and spent hours and hours trying to understand why it works but couldn't figure it out. Assuming my understanding is correct that f1 stores the max length of ...
1
vote
0
answers
76
views
Seeking a Linear Time Complexity Algorithm for Maximum Strength Query with Variable Range
I'm tackling a challenging problem and seeking assistance to find a solution with linear time complexity (Theta(n)). The objective is to compute the maximum strength a creature can harness from a ...
1
vote
1
answer
143
views
how to apply sliding window in deep learning LSTM using MATLAB Deep Learning Toolbox
i am currenty using MATLAB Deep Learning Toolbox to build a LSTM-Network to do timeseries regression. Since my data has 12 features and 1 response. The input size of the sequenceInputLayer is set to ...
0
votes
1
answer
45
views
Are you getting TLE in this problem Smallest window containing 0, 1 and 2?
enter image description here
Problem link: https://www.geeksforgeeks.org/problems/smallest-window-containing-0-1-and-2--170637/1
Getting TLE after using the sliding window technique that takes O(N) ...
1
vote
1
answer
132
views
Getting 2-dimensional sliding windows from an image in Julia
I need to get several sliding windows from an image using the Julia programming language. I am newcomer to the language and having a hard-time finding a performant solution.
The problem: Lets say I ...
0
votes
0
answers
102
views
Can you run a sliding window analysis on a raster in R and specify window size that is not a multiple of the cell size?
I have several covariate layers that vary in resolution I would like to run sliding window analyses on all of these layers with a window size of 800m. This window size is important to maintain exactly ...
-1
votes
1
answer
61
views
Is there any function for sliding window just like in matlab but for python?
I need a function that selects all the data from a 2D array in a square window but I want to do this in Python. Is there any specific function for it?
median_x_array = median_coords_3d_array[:, :, 0] ...
0
votes
0
answers
90
views
Finding sums of all subarrays of an array
This is a snippet from this code to finding sums of all subarrays of a given array, but this doesn't work as intended as the problem seems to be lying with pre-incrementing value of i in the equation.
...
-1
votes
1
answer
140
views
Speed up matching between a sliding window and a list
I have an odd length window and a array and I need to find the index of the array where the window is centered and matches more. So far I am doing it with the following code. Is it possible to speed ...
0
votes
1
answer
665
views
To find Maximum Average Subarray
This is a Leetcode problem,
You are given an integer array nums consisting of n elements, and an integer k. Find a contiguous subarray whose length is equal to k that has the maximum average value and ...
0
votes
1
answer
113
views
How do I create a sliding window of 5 bits in a single byte?
Here is a visual of what I want to have happen 5 bit sliding window
In words, I want a sliding window of 5 bits. I need to store a history of 5 events within a single byte. I'm using the 5 most ...
0
votes
1
answer
109
views
How can I reproduce animation of Backtesting with intermittent refit over time?
I'm experimenting with 1D time-series data and trying to reproduce the following approach via animation over my own data in GoogleColab notebook.
It's about reproducing the animation of this approach: ...
2
votes
1
answer
378
views
Leetcode 424. Longest Repeating Character Replacement: Right Pointer Incrementation
I'm trying to solve Leetcode 424. Longest Repeating Character Replacement.
Why is this code not working, I cannot get my head around it.
class Solution:
def characterReplacement(self, s: str, k: ...