All Questions
88 questions
0
votes
1
answer
91
views
How to optimize this code: Leetcode input was unexpectedly ( Memory Limit Exceeded )
Leetcode question: Given a binary array nums, return the maximum length of a contiguous subarray with an equal number of 0 and 1.
Leetcode entered a very long input of to the function and its IDE ...
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 ...
20
votes
3
answers
1k
views
Efficient way to find sum of largest x elements in a subarray
I have a 1-indexed array of positive integers, and I want to make several queries to it, all in the form, 'what is the sum of the largest x integers in the subarray 1 to y inclusive?' This array is ...
-5
votes
1
answer
162
views
how this tricky problem could be solved in python for creating subarray
write a program to create subset of given array the value inside the array should be target value and length of array should be k
program that i have tried
arr = [1, 2, 8, 6, 4, 9, 5]
k = 3
target = ...
1
vote
2
answers
482
views
Count subarrays in A with sum less than k
For the question below:
Given an array A of N non-negative numbers and a non-negative number B,you need to find the number of subarrays in A with a sum less than B.
I have found 2 solutions:
Brute ...
-1
votes
2
answers
110
views
How to do a consecutive subarrays in JavaScript [duplicate]
I am studying algorithms in JavaScript; I am trying to generate consecutive subarrays but I don't know to do it.
I have the following array:
[1, 2, 3, 4, 5, 6, 7, 8, 9]
I want to split it in ...
3
votes
0
answers
126
views
Resetting an array of numbers by repeated subtraction from a sub-array
There is an array of numbers between 0 and 6 (base 7). For example {0 4 6 2 2 0 3 1}. Its maximum length can be 501 elements.
Each step we can subtract a number from any number of elements. All of the ...
0
votes
1
answer
945
views
Cut a sequence of length N into subsequences such that the sum of each subarray is less than M and the cut minimizes the sum of max of each part
Given an integer array sequence a_n of length N, cut the sequence into several parts such that every one of which is a consequtive subsequence of the original sequence.
Every part must satisfy the ...
0
votes
0
answers
32
views
Why is my solution to the k subarray product problem not working?
I implemented a solution that uses xor to know if a product has been computed before. It recursively gets all the possible products. Here's the code:
#include <stdio.h>
int driver(int *arr, int ...
1
vote
3
answers
2k
views
Algorithm to generate all Subarrays from initial Array
How to generate all subarrays from an initial array?
Let's consider an array: [1,1,1,1].
I would like to generate all possible subarrays (in no particular order).
Expected result:
[1], [1], [1], [1],
...
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
361
views
Question Regarding Binary Subarrays With Sum
I was interested in finding a solution to a problem that provided a binary array called nums - which, for example, could consist of 10101, or 00000, or any such combination of 0 and 1's - from this, ...
1
vote
1
answer
744
views
Total number of subarrays in an array having average greater than or equal to k
Given an array A of size N and an Integer k. Find the total number of subarrays with different sizes having an average greater than or equal to k.
Constraints :
1 <= N <= 10^5
-10^9 <= A[i] &...
0
votes
2
answers
1k
views
Concurrent Array Functions
I have a function that takes an array of sub-arrays containing number strings and returns an array with the highest number from each sub-array:
const largestOfFour = arr => {
arr.map(e =...
0
votes
0
answers
54
views
How to find length of longest continuous subarray such that first and last element are minimum and maximum?
How to find longest continuous subarray S[i..j] of array A[0..n-1] such that S[i] is minimal and S[j] is maximal element in S. It should be solved in O(N) or O(n log n).