Questions tagged [sub-array]

A sub-array is a subset of an array.

434 questions
1
vote
0 answers

How to add array in complex multidimansional array in exact subarray if existis or not with unknow depth in php

Here is my problem. I have an complicated multidimensional array with different depths. Everything on Stackoverflow I tried, failed. I tried with array_push, array_merge, array_combined, foreach, for etc. Code I have is BS. The array (part of it…
1
vote
0 answers

What is the approach to solve spoj KPMATRIX?

The problem link is here. The problem is basically to count all such sub matrices of a given matrix of size N by M, whose sum of elements is between A and B inclusive. N,M<=250. 10^-9<=A<=B<=10^9. People have solved it using DP and BIT. I am not…
sherelock
  • 464
  • 5
  • 9
1
vote
0 answers

use memcpy and begin() to copy a sub-array of a multidimensional array

I am trying to use memcy to copy an sub-array of an updated array A into an array B. Both A and B array have the same number of dimensions. The data going into array A is in the order of A.get_size(3) (Let's call dimension N here). Each update N…
Cii
  • 133
  • 8
1
vote
1 answer

PHP foreach in subarray affecting another element of parent array

I've got this array (print from point [A] in code below): Array ( [codigo] => [titulo] => Array ( [0] => musi [1] => bach ) [titulo_operador] => OR [resumo] => [autor] => [ano_min]…
1
vote
1 answer

Extract two sub array values in mongodb by $elemMatch

Aggregate, $unwind and $group is not my solution as they make query very slow, there for I am looking to get my record by db.collection.find() method. The problem is that I need more then one value from sub array. For example from the following…
Sajjad Ahmed
  • 349
  • 1
  • 3
  • 12
1
vote
1 answer

Sorting and displaying values systematically from a multi-dimensional PHP array

Below I've appended the $var_dump of an array that I've created through user-actions involving an HTML form. I'm certainly willing to consider other strategies for achieving the final effect (and I'm not, to be honest, positive that it would not be…
CK MacLeod
  • 932
  • 6
  • 10
1
vote
2 answers

PHP Complete sub array with the same number of elements

I have an array as following. Array ( [A] => Array ( [y] => 2014-11-26 [x] => 1 [zzz] => 2 [ww] => 1 ) [B] => Array ( [y] => 2014-11-27 [zzz] => 2 ) …
O Connor
  • 4,236
  • 15
  • 50
  • 91
1
vote
1 answer

Overflow error in Python Code for Maximum Subarray Using Recursion

My program seems to not work for this code. I'm new to Python so I'm not sure if this is a language related error. I'm currently using Python 2.7.8. A = [-1, -2, 3, 4, -5, 6] def main(): a,b,c = find_maximum_subarray_recursive(A) …
so908
  • 25
  • 1
  • 6
1
vote
2 answers

Group rows by one column, only create deeper subarrays when multiple rows in group

I have a multi-dimensional array like this: Array ( [0] => Array ( [id] => 1 [email_id] => ok@gmail.com [password] => test ) [1] => Array ( [id] => 2 …
DarkRose
  • 125
  • 4
  • 12
1
vote
2 answers

Maximum Subarray variation

I have to solve a problem much like the maximum subarray problem. I have to find the largest subarray whose average is bigger than k. I thought the following trick. I can transform my array A[] of size n to a B[] where B[i] = A[i] - k. So now the…
Paramar
  • 287
  • 1
  • 5
  • 22
1
vote
2 answers

MongoDB PHP insert into sub-array

Ok, not sure if mongodb can do this, but what I need is for the following JSON to be inserted into my currency DB. The part we want to update is exchangehistory, we need to keep all the history of the exchange rates for that day. and the next day…
RussellHarrower
  • 6,470
  • 21
  • 102
  • 204
0
votes
2 answers

Leetcode 643. Maximum Average Subarray I

Question - You are given an integer array nums consisting of n elements, and an integer k.Find a contiguous subarray whose length is equal to k that has the maximum average value and return this value. Test Case- nums = [1,12,-5,-6,50,3], k = 4 The…
Gargi
  • 3
  • 1
0
votes
1 answer

SubArray selection in swift

I want to do a sub-array selection Python-like (ArraySlice) in Swift. This is working for me, but I know it's not nice. To make it work I used .suffix embedded to .prefix method. I'm wondering if there's an easier or cleaner method to accomplish…
ccmsd18
  • 58
  • 7
0
votes
1 answer

Continuous subarray with given sum

I am trying to create a continuous subArray from a given array which is equal to the given sum and return the first and last index as an ArrayList. This is the solution i could think of which actually passed 52 testcases but failed for a really…
0
votes
0 answers

Counting segments containing certain subsegments

I have an array of N integers, and I have to find the number of such segments that they contain within themselves segments whose cumulative sum is equal to zero. For example, if I have an array [5, -5, 5], then [0,1], [1,2], [0,2] (the left number…