All Questions
5 questions
1
vote
3
answers
150
views
Sum of maximum element of all subarray not including the first and last element
I am trying to make an algorithm that calculates the sum of each maximum element in a subarray not including the first and last elements. The naive approach is obvious but I do not want that.
Here is ...
0
votes
1
answer
412
views
How to find largest subarray of sum k
Let's say you have given an array of size N, which can have a positive and a negative number.
we need to return the length of the largest subarray of sum equal to k. I tried to use the sliding window ...
0
votes
1
answer
87
views
How to solve this permutation related problem in O(n^2) complexity?
There are 2 arrays A and B with lengths N and M you have to delete 1 element at a time from B and check if there exists a permutation of B in A
Explanation:
Example:
N = 5
A = [1,2,2,1,1]
M = 3
b = [1,...
3
votes
3
answers
5k
views
Find number of distinct contiguous subarrays with at most k odd elements
Given an integer array nums, find number of distinct contiguous subarrays with at most k odd elements. Two subarrays are distinct when they have at least one different element.
I was able to do it in ...
1
vote
1
answer
186
views
Possibly simpler O(n) solution to find the Sub-array of length K (or more) with the maximum average
I saw this question on a coding competition site.
Suppose you are given an array of n integers and an integer k (n<= 10^5, 1<=k<=n). How to find the sub-array(contiguous) with maximum ...