Questions tagged [sub-array]

A sub-array is a subset of an array.

434 questions
1
vote
2 answers

print subsets in alphabetic order, without sorting

I am supposed to receive n, and create an array of 1 to n, then print the subsets in alphabetic order, but the goal is to create them in an alphabetic order (no array sorting) , for example for n=3 the right order would be: {} {1} {1,2} {1,2,3}…
arman5592
  • 41
  • 8
1
vote
2 answers

Kadane algorithm in Scala explanation

I am interested in learning how to implement the Kadane (maximum subarray sum) algorithm in scala with foldLeft function. I run through this example on stack overflow, however I am not sure I understand what the algorithm does exactly. This is how…
1
vote
0 answers

Largest smaller value in left subarray for all elements

I was solving the question of Longest Increasing Sub-sequence using dynamic programming with O(n^2) as per following pseudocode (Basically we are doing bottom-up approach to get length of largest increasing sub-sequence that ends at index i for all…
ATK
  • 358
  • 3
  • 17
1
vote
1 answer

How to efficiently operate on sub-arrays like calculating the determinants, inverse,

I have to to multiple operations on sub-arrays like matrix inversions or building determinants. Since for-loops are not very fast in Python I wonder what is the best way to do this. import numpy as np n = 8 a = np.random.rand(3,3,n) b =…
Jup Pes
  • 13
  • 4
1
vote
2 answers

Finding Maximum non-negative Subarray in python

I've tried to find the sub-array(s) from a given which contain elements of maximum sum than any other sub array. Below function has parameter as input a and the output needs to be returned. There can be more than one subarray as their maximum sum…
1
vote
1 answer

Find maximum subarray using binary search

You have two arrays arr1 and arr2, you want to find the maximum size of a subarray which is both a subarray of arr1 and arr2 For example: arr1 = [3,2,1, 4,5] arr2 = [1,2,3,4,3,2,1] return is 3 ([3,2,1]) This problem has a binary search solution…
Yongcong Luo
  • 53
  • 1
  • 9
1
vote
0 answers

Find the index which partitions the arrays into 2 subarrays whose absolute difference of their sums is minimized

We have to find an index 'x' such that the absolute difference between (A[1]+A[2]+..+A[x]) and (A[x+1]+A[x+2]+..+A[n]) for some x , is minimized. I came across this post. Here the author has asked to minimize the produc of the subarrays, so in my…
Avi solanki
  • 53
  • 1
  • 6
1
vote
2 answers

How to find the two largest disjoint subarrays of a given length?

I need to write a function that takes in as input an array A of positive integers, a positive integer B and a positive integer C. The function should then return the total sum of the elements of two disjoint subarrays of A of length B and C that…
tommsyeah
  • 121
  • 3
  • 10
1
vote
3 answers

How to split an array of arrays?

I have this array that contains some other arrays in Python, but I need only the first elements of each mini array inside the main array. Is there some method to do that? Example: array = [['a','1'], ['b','2'], ['c','3'], ['d','4'], ['e','5']] I…
1
vote
1 answer

Combine Sub-array values into a single array withing an array

I may not word this issue properly, so here's what am trying to achieve. array { [0]=> { ["Abilities"]=> { ["Numerical"]=> 3 } } [1]=> { ["Abilities"]=> { ["Verbal"]=> 1 } } [2]=> { ["Domain"]=> {…
GauthamK
  • 174
  • 2
  • 12
1
vote
1 answer

Generating a constructor

My assignment asks to create a constructor that takes no input. The constructor initializes the two non-static attributes in order for them to represent a standard deck or cards. Note that this means that the array of Cards should be initialized…
Elizabeth
  • 35
  • 1
  • 6
1
vote
1 answer

Make sums of left and right sides of array equal by removing subarray

C program that finds starting and ending indexes of subarray to remove to make given array have equal sums of left and right side. If its impossible print -1. I need it to work for any array, this is just for testing. Heres a code that finds…
haxor567
  • 11
  • 3
1
vote
1 answer

Modifying values of a sub-array in python

I want to modify the values of a sub-array in Python but it does not work the way I would like to. Here is an example, first let us consider the numpy arrays : A = np.reshape(np.arange(25),(5,5)) and B = np.ones((2,3)) If we check the values of A…
Seb
  • 43
  • 7
1
vote
1 answer

Traversing all the subarrays of a 2-D array

I have a 2-D array given of size P*Q and I have to answer K questions based on the array. The 2-D array given consists of numbers 0 and 1. For each question, we have to count the maximum size of any square subarray in which no two same elements are…
1
vote
1 answer

Combine some php sub-arrays, with condition

$routes array: [admin/login] => Array ( [0] => POST|AJAX [1] => admin/login [2] => admin/login ) [admin/logout] => Array ( [0] => POST [1] => admin/logout [2] => admin/logout …