A sub-array is a subset of an array.
Questions tagged [sub-array]
434 questions
2
votes
3 answers
Remove unwanted elements from subarrays in multidimensional array
I have a multidimensional array like this:
[
[
'id' => 1,
'name' => 'John',
'address' => 'Some address 1'
'city' => 'NY'
],
[
'id' => 2,
'name' => 'Jack',
'address' => 'Some address…

Johan
- 23
- 2
2
votes
4 answers
Print all contiguous subarray
I want to write a recursive function to add all of the contiguous subarrays in a list.
The function works but there is some duplication. I wanted to know if there is a way to avoid this.
def numSubArray(array, result):
if len(array) == 0:
…

Raphael00
- 61
- 1
- 9
2
votes
3 answers
Return an array of arrays of key-value pairs WITHOUT using Object.entries()
I am trying to write a function that accepts an object and returns an array of arrays of key-value pairs. I also cannot use the Object.entries() function.
Example: For var obj = { a: 1, b: 2, c: 3 }; I would want to return: [["a",1], ["b",2],…
user5617839
2
votes
0 answers
How do I neatly select a numpy sub-array in 1 line?
...couldn't find an answer so hope its not a duplicate...
I have an array arr and want to select a sub-array sub_arr using specified indices (e.g. idxs = [1,3,4,6]). My inuition was to set sub_arr = arr[idxs,idxs], however this returns a 1-D array…

Highland_Cattle
- 21
- 1
2
votes
1 answer
Find the length of the longest repeated subArray
Given an array of integers between 1 and 10^5 find in the best time and space the lenght of the longest repeated subArray.
I was thinking in making binary search but i want to hear some suggestions. Thanks for helping !

CrazyMath65
- 23
- 3
2
votes
3 answers
How to get a sub-array in python?
So I have an array, and I'm trying to get a sub-array from it.
x = np.arange(0,100).reshape((10, 10))
array([[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
[20, 21, 22, 23, 24, 25, 26, 27, 28,…

Fire
- 301
- 1
- 2
- 9
2
votes
1 answer
not able to solve edge case in number of contiguous subarrays with sum k
I have been trying to solve the "Subarray Sum Equals K" problem on leetcode. However I am not able to solve some test cases with the following code:
from collections import defaultdict
class Solution(object):
def subarraySum(self, nums, k):
…

boomselector
- 45
- 9
2
votes
1 answer
Find a subarray from a array that equals some value X
Background
You are given an array that includes positive and negative numbers.
You are to find a subarray within the array that equals some value X.
The input is the array and the X value.
The output is the starting and ending index of the…

Dinero
- 1,070
- 2
- 19
- 44
2
votes
1 answer
Count Number of distinct subarrays
I recently came across this question in one of the coding interviews. The question is as follows:
Given an array A[] of n numbers and a number k, count the total number of distinct subarrays such that each subarray contains at most k odd elements.
1…

User_Targaryen
- 4,125
- 4
- 30
- 51
2
votes
1 answer
Length of minimum subsequence that spans entire length of array?
I'm given an integer array of length N, with elements representing the spans it could cover from 0 to N-1. so for an element a[i] the element spans a range from max(i-a[i],0) to min(i+a[i],N-1).
How to find the length of smallest subsequence that…

Mega Mbo
- 43
- 7
2
votes
3 answers
Maximum sum of contiguous sub-sequence with length at most k
I am trying to modify the Kadane Algorithm in order to solve a more specific problem.
def max_Sum(arr, length, k):
if length < k:
print('length of array should be greater than k')
res = 0
for i in range(0, k):
res += arr[i]
current_sum =…

rockmyboat
- 157
- 2
- 10
2
votes
1 answer
How to improve my php sub_array code using INNER JOIN to display data on DataTables?
I'm using this CRUD tutorial https://www.webslesson.info/2017/01/php-pdo-ajax-crud-with-data-tables-and-bootstrap-modals.html to make some tests and i would like to improve it including 2 columns related to another tables on MySql.
I'm working with…

Michel Xavier
- 133
- 3
- 14
2
votes
2 answers
Compute sum of elements of sub-arrays based on their position and first element of array
Having a matrix which contains many sub-arrays. Each array has the same length and each first element of them is a string followed by numeric elements having this form:
myArray = [
["revenues", 10, 20, 30],
["expenses", 1, 1, 1],
…

Leo Messi
- 5,157
- 14
- 63
- 125
2
votes
2 answers
Can pointer to subsection be used out of its original bounds in Fortran
Is it valid to do something like:
real(kind=rk), allocatable, target :: arr(:,:)
real(kind=rk), pointer :: ptr(:,:)
allocate(arr(10, 10))
ptr => arr(5:7, 5:7)
arr = 0
ptr(-1, 4) = 1
e.g. create pointer to array subsection and then access indices…

Vladimir Kikhtenko
- 23
- 4
2
votes
3 answers
Check if every sub-array of a multidimensional array contains an element or not
I have a multidimensional array whose depth is uncertain or let's say depends on how many categories & sub-categories(& sub-sub-categories) are there in magento website, as I calling function $product->getCategoryIds().
Now let's assume I get all…

VST
- 131
- 1
- 10