Questions tagged [sub-array]

A sub-array is a subset of an array.

434 questions
2
votes
2 answers

Swift: Mutating array in struct

I am trying to create a Matrix class in Swift but I am getting an error on the self.data[row * columns..<(row + 1) * columns] = data line in my setRow() function. The error is 'Cannot assign value of type '[Double]' to type 'ArraySlice'' struct…
BenJacob
  • 957
  • 10
  • 31
2
votes
2 answers

how to check if any subarray doesn't contain an item from other subarray? Ruby

I have an array animals = [ [{"name" => "Alex", "spices" => "dog", "vname" => "colour", "value" => "black"}, {"name" => "Alf", "spices" => "dog", "vname" => "colour", "value" => "white"}, {"name" => "Sonia", "spices" => "dog", "vname" =>…
ag.lis
  • 31
  • 1
2
votes
4 answers

How to add subarrays to itself? Ruby

I have an array containing of subarrays like this: arr = [[{"big" => "2055", "small" => -"-10", "thin" => "i"}, {"big" => "2785", "small" => "0", "thin" => "l"}], [{"big" => "7890", "small" => "3", "thin" => "t"}, {"big" =>…
mia102aim
  • 103
  • 1
  • 7
2
votes
4 answers

Group 2d array by column, preserve multiple other column values and push 2 column values into subarrays

I have a array with repeated values like this: [ [ 'id' => 112, 'name' => 'John', 'country' => 'Spain', 'age' => 24, 'company' => 'One', 'price' => 10 ], [ 'id' => 112, …
kurtko
  • 1,978
  • 4
  • 30
  • 47
2
votes
2 answers

How to rearrange an array by subarray elegantly in numpy?

Let's say I have a 3-D array: [[[0,1,2], [0,1,2], [0,1,2]], [[3,4,5], [3,4,5], [3,4,5]]] And I want to rearrange this by the columns: [[0,1,2,3,4,5], [0,1,2,3,4,5], [0,1,2,3,4,5]] What would be an elegant python numpy code for doing…
StatsNoob
  • 360
  • 1
  • 5
  • 15
2
votes
2 answers

Filter subarrays in an array

I must be losing my mind. Suppose I have an array of arrays. I want to filter the subarrays and end up with an array of filtered subarrays. Say my filter is "greater than 3". So let nested = [[1,2],[3,4],[5,6]] // [[],[4][5,6]] After some…
rswerve
  • 169
  • 1
  • 3
  • 7
2
votes
2 answers

How do I print the number of negative subarrays from a given array?

Problem Statement: Given an array of n integers, find and print its number of negative subarrays on a new line.(A subarray is negative if the total sum of its elements is negative.) Sample Input 5 1 -2 4 -5 1 Sample Output 9 Result that my code…
2
votes
2 answers

Boolean expression for if list is within other list

What is a efficient way to check if a list is within another list? Something like: [2,3] in [1,2,3,4] #evaluates True [1,5,4] in [5,1,5,4] #evaluates True [1,2] in [4,3,2,1] #evaluates False Order within the list matters.
Sarah Pierson
  • 149
  • 10
2
votes
2 answers

Range of maximum product subarray (Kadane algorithm variant)

I have been trying to get the range of a Maximum Product of a subarray (studying for job interviews). This has been already asked here (but no valid answers have been provided). Getting range of max product subarray using Kadanes algorithm The…
Sanjay
  • 23
  • 5
2
votes
2 answers

Split array based on sum of the values of each element

Suppose the elements of an input array are arranged in ascending order, as in this sample: int[] a= {23,24,25,30,34,36,40,41,43,45,50}; I need to split the array into different sub-arrays. Each sub-array will contain elements such that their sum…
ramansingh
  • 45
  • 8
1
vote
2 answers

Ruby - split and rename subarrays

As the title says... if I have an array containing subarrays is it possible to split the array and rename the new split arrays? I know I could simply type new_array=array[0] and so on but the problem is that the original array containing the sub…
JoMojo
  • 404
  • 1
  • 7
  • 22
1
vote
0 answers

Subarray XOR having odd number of set bits

How can I find the number of subarrays where bitwise XOR of the element of the subarray has odd number of set bits. Basically I need to find the solution in linear time. I could solve in O(N^2). What concept is required to solve this problem?
1
vote
3 answers

How to get the arrays not contained in another array?

I have two Python arrays with arrays inside: first = [[0,10],[0,11],[0,12],[0,13]] second = [[0,10],[0,11]] and I want to get as a result the array that is in the first one, but not in the other: difference(first,second) #returns…
BSDash
  • 13
  • 2
1
vote
2 answers

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 force: let count = 0; for (let i=0; i
Ashy Ashcsi
  • 1,529
  • 7
  • 22
  • 54
1
vote
1 answer

Sumproduct of sub-arrays in excel

I need to find a performant and smart way to redesign the formula or the tables on which it depends (COSTO_DUMMY and GG_TARGET). Can you help me, please? I can add new support tables if…