Questions tagged [sub-array]

A sub-array is a subset of an array.

434 questions
0
votes
1 answer

How can the sub-array of an array be filtered in JSONata

In the following array how can the object with "step":"2" be removed from the sub-array "subGroupB" only when "code":"code-333"? { "mainGroup":[ { "subGroupA":{ "id": "id-111", "code": "code-111" }, …
HobieKatz
  • 37
  • 8
0
votes
2 answers

i have initialized a variable with zero at the top of the function so during a loop the value changes?

public class maxsubarraysum { public static void main(String[] args) { int numbers[] = { 1, -2, 6, -1, 3 }; printmsasum(numbers); } public static void printmsasum(int numbers[]) { int currsum=0;//declared and…
0
votes
1 answer

How can I find the largest subarray sum if all the elements are negative and I have set the maxSum to 0, which is used to compare other elements?

Can someone help me with this. My code is working fine but consider a case of [-2,-1]. Since my maxSum is set to 0. My output is coming 0 instead of-1. How should I modify my code? Sample i/o: Input: nums = [-2,1,-3,4,-1,2,1,-5,4] Output:…
Shreyansh
  • 21
  • 1
  • 8
0
votes
1 answer

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 following: The sum of each part is not greater than…
Sharhad
  • 63
  • 8
0
votes
0 answers

Max Sum of All K consecutive sub arrays from 1 to n of an array using sliding window

This is my code and it does well for positive numbers given in the array but when one of the input numbers is negative it doesn't work #include int main() { int n; scanf("%d", &n); // Getting the length of array int…
0
votes
0 answers

Sub array with a given sum

(The given problem is referred from : https://practice.geeksforgeeks.org/problems/subarray-with-given-sum-1587115621/1?page=1&difficulty[]=0&curated[]=1&sortBy=submissions ) I tried a solution to the above problem but it failed for large values for…
0
votes
1 answer

Divide Array in subarrays by local peaks

Hey there i have an numpy array y with over 4000 values. data=pd.read_csv('samplesdata.csv',sep=";", decimal=",",encoding='latin-1') sensor_data=data[['Euklidische Norm']] sensor_data = np.array(sensor_data).ravel() sensor_data = sensor_data -…
0
votes
0 answers

Find the maximum sum among all segments formed after removing one element in every iteration

An array A of size N having positive integers is given. Another array B having permutation of numbers 1 to N is given. Your task is to perform N steps : At i-th step, you have to remove element A[B[i]] from array A. After removing the elements,…
user972404
  • 11
  • 3
0
votes
0 answers

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 int driver(int *arr, int k, int n){ int counter=0; int sbc=0; …
0
votes
3 answers

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], [1, 1], [1, 1], [1, 1], [1, 1, 1], [1, 1,…
PatPanda
  • 3,644
  • 9
  • 58
  • 154
0
votes
0 answers

Numpy subarray given by center and radius

Is there a function or more concise notation to get b or bb in the code snippet below? import numpy as np a = np.arange(12).reshape(3, 4) c = (1, 2) r = 1 b = a[c[0]-r:c[0]+r, c[1]-r:c[1]+r] bb = a[c[0]-r:c[0]+r+1, c[1]-r:c[1]+r+1] The objective…
Paul Jurczak
  • 7,008
  • 3
  • 47
  • 72
0
votes
1 answer

How to search a matrix/array for a subarray containing a specific string (Javascript)

I have a matrix along the lines of this: const chartypes = [ ["bad boy","masc"], ["celebrity","neut"], ["activist","neut"], ["expert","neut"], ["princess","fem"], ["manager","neut"] //, etc. ]; For various complex reasons, I…
corvidia
  • 11
  • 3
0
votes
1 answer

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 algorithm but soon I found out it won't work here…
0
votes
0 answers

Time complexity related to subArray problem

How we can decrees time complexity of finding subarray of a given array in O(n) from O(n^3) void subArray(int arr[],int n) { int i=0,j,k; while(i
0
votes
1 answer

Sub arrays in python

How to print the sum of user desired subarray from a given list [1,2,3,4,5,6] using slice method in python ? I've got success till the slice method and displaying the subarray , but I am not able to do the sum operation as it is showing error for…
Kake_000
  • 1
  • 1