A sub-array is a subset of an array.
Questions tagged [sub-array]
434 questions
1
vote
1 answer
Check if item exists in same position in each nested list - Python
I'm writing a Connect Four script. The script takes a list of moves as input ("A_Red, "B_Yellow", "G_Red", etc), which I'm sorting into a matrix. Each nested list represents a column of the board with "A" being the first nested list (or column), and…

CunnyFunt
- 105
- 7
1
vote
2 answers
Sort data in column of a multi-dimensional array in a descending direction while preserving keys
I have the following array that I'm attempting to sort each scores array by answer from high to low.
$array = [
503 => [
'scores' => [
4573 => ['answer' => 100],
4574 => ['answer' => 60],
4575 =>…

Chris Ediger
- 13
- 4
1
vote
1 answer
Time Limit Exceeded: How can I optimize my code in Javascript?
I am trying to solve Sum of Subarray Ranges question on leetcode, it's giving me Time Limit Exceeded so I guess my code isn't optimized well and needs more efficient solutions. But I am not so good at it so to be specific how can I remove two…

Harsh Mishra
- 862
- 3
- 15
- 29
1
vote
2 answers
reversing sub arrays with nested loop Javascript
I wants to reverse the array with sub arrays with nested loops. I do not wants to use the reverse function. But every-time I do that I get this a type-error.
anyways here is my code
let arr = [[1,2,3],[4,5,6],[7,8,9]];
for(let i = arr.length - 1;…

user218592
- 35
- 4
1
vote
1 answer
Retrieve multiple ArrayFire subarrays from min/max data points
I have an array with sections of touching values in it. For example:
0 0 1 0 0 0 0 0 0 0
0 1 1 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 2 2 2 0 0
0 0 0 0 0 0 0 2 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 3 0 0 0 0 0 0 0
0 0 3 0 0 0 0 0 0…

AAG
- 235
- 1
- 11
1
vote
5 answers
Finding the subarray with the Maximum sum in the given ArrayList
The problem description:
Given an ArrayList of Integers. Find a subarray with the maximum sum of any potential subarray within the ArrayList.
A subarray a is a combination of consecutive numbers.
The subarray can be of any length n, where the size…

stucklucky
- 75
- 1
- 1
- 9
1
vote
2 answers
how to get elements in sub-array of a numpy array in python
I'm getting in trouble with reading the entries of a sub-array of a numpy array, in python. I've got something like this:
a = np.array([ [453,254,[1,2,3,4,5]], [743,251,[10,20,30,40,50]], [127,393,[11,22,33,44,55]] ], dtype=object)
and I need to…

urgeo
- 645
- 1
- 9
- 19
1
vote
4 answers
Extracting sub-arrays safely/idiomatically in C#
I am building a natural language processor in C#, and many 'words' in our database are actually multiple-word phrases that refer to one noun or action. Please, no discussion on this design call, suffice it to say it is not changeable at this time. …

tmesser
- 7,558
- 2
- 26
- 38
1
vote
2 answers
Create and find highest value in subarraylist
I have an Arraylist of the Cells from an Excel sheet. I want to create subarraylists of size 50 from the Arraylist of Cells I actually have, beginning from the index of 1590 and ending with size()-700.
I want to get the highest number from every…
user15841461
1
vote
1 answer
extract value from subarray and combine with upper value using jq to csv
I have a json file with a sub-array and I want to get each sub-array with the same id in separate lines.
json:
{
"success": true,
"status": {
"http": {
"code": 200,
"message": "OK"
}
},
…

Chrno
- 13
- 3
1
vote
1 answer
Reduce a sub array into an object with a custom formula, MongoDB aggregation
I'm looking for a way to reduce an array of elements into an object based on a custom requirement.
Considering a collection like:
[
{
name: "David",
checkins: [
{
_id: "612e162d439cb04934d13f9e",
in_at:…

Scoopa
- 45
- 12
1
vote
1 answer
Removing subarray from array with splice
I am using splice method to remove a subarray from an array with the following code:
for(let i = 0; i < cid.length; i++)
{
if(coinsValue[cid[i][0]] < troco && cid[i][1] > 0)
available += cid[i][1]
…

izzypt
- 170
- 2
- 16
1
vote
0 answers
find the maximum sum subset array from an array such that its each powerset sum is not divisible by M and can consecutively choose at most K jumps?
Given an array
A=[6,3,2,1,9,10,2,11]
My task is to select elements from the array such that sum of the elements which I pick should not be divisible by M=6 and I can skip at most K=2 elements consecutively. My final goal is to select the elements…
1
vote
1 answer
Maximum difference of sum of odd and even index elements of a subarray
Given an array of N integers (can be positive/negative), calculate the maximum difference of the sum of odd and even indexed elements of any subarray, assuming the array follows 0 based indexing.
For Example:
A = [ 1, 2, -1, 4, -1, -5 ]
Optimally…
1
vote
2 answers
Given an array of N elements. The task is to find the length of the longest subarray such that sum of the subarray is even
For the given question I have come up with the following code. But it doesn't seem to solve the problem. Please have a look and suggest changes.
#include
#include
using namespace std;
int main()
{
int n;
cin>>n;
…

Diksha Nasa
- 135
- 3
- 13