Questions tagged [sub-array]

A sub-array is a subset of an array.

434 questions
-2
votes
1 answer

Dont want the 1st position in array

I have one array, say String[] a={a,b,c,d,e,f,g} I want this array in second array but without the first element in the array, for example String[] b{b,c,d,e,f,g} How do I achieve this?
anuj
  • 429
  • 3
  • 7
  • 14
-3
votes
2 answers

Find all the Subarrays in O(nlog(n)) time complexity JavaScript

how to get all the subarrays in O(nlog(n)) time complexity using javaScript I try with a nested loop but the time complexity is in O(n*n). I heard about some prefix solutions but have no information
Ujjwal
  • 1
  • 3
-3
votes
1 answer

How can I check if a sorted subarray with size 'k' , is contained in an bigger sorted array with size 'n' (k <= n) this complexity O(logn)?

I would like to find if a sorted subarray v' with size 'k' is contained in another sorted array with size 'n'. We know that k <= n. However, it would be so easy with a double for loop or something similar, however I would like to implement it with…
j.j.3
  • 15
  • 4
-3
votes
2 answers

How to get sub-arrays containing same elements from an array?

I have an array containing duplicate elements. What I need is to get those duplicate elements to new sub-arrays. For example: I have the main array, array = [ a, b, c, a, d, c, c, b, a ] what I need is to get this array divide into new sub-arrays…
-3
votes
2 answers

PHP define array with sub arrays as an index

I am using a PHP file to define some data to be used in another app. I thought this was a valid way to declare my arrays.. with sub-arrays as indexes. But apparently not.. //question 1 $quiz['question'][0] = "xxx"; $quiz['question'][0]['answer'][0]…
whispers
  • 962
  • 1
  • 22
  • 48
-3
votes
3 answers

Is there a way to get a named key/value from SUBARRAY without knowing the main key?

Short: Is there a way to get a named key/value from SUBARRAY without knowing the main key ? Long: Ive got a foreach loop that extracts text-files & turns them into individual / single arrays (resetting the array between each…
G Stewpot
  • 97
  • 1
  • 2
  • 10
-3
votes
1 answer

php find gaps and build an array

I have this array ( [0] => 1976, [1] => 1977, [2] => 1978, [3] => 1979, [4] => 1980, [5] => 1981, [6] => 1982, [7] => 1983, [8] => 1990, [9] => 1991, [10]…
Jelqui
  • 11
  • 2
-3
votes
6 answers

Can I Sort sub-array by its value alphabetically in php?

I have $mainArr array and I want result as $resultArr. $mainArr = array( 0 => array(125 => 'B', 127 => 'A', 178 => 'Z', 78 => 'G'), 1 => array(111 => 'X', 127 => 'K', 108 => 'J', 708 => 'P'), 2 => array(125 =>…
-4
votes
1 answer

Zero Subsequences problem - What's wrong with my C++ solution?

Problem Statement: Given an array arr of n integers, count the number of non-empty subsequences of the given array such that their product of maximum element and minimum element is zero. Since this number can be huge, compute it modulo 10 ^ 9 + 7 A…
hecker
  • 9
  • 4
-4
votes
1 answer

Value of type 'PodPost' has no member 'episode'

Also don't understand why the downvotes So the following code is saying it has no member of episode which is correct because the JSON gets passed to PodEpisode first. Then need to pass it to the last subarray struct PodPost: Codable { var…
RussellHarrower
  • 6,470
  • 21
  • 102
  • 204
-4
votes
1 answer

Problems with Java Arrays.sort() on sub-arrays -- is this a bug?

I have noticed odd behavior when using Java Arrays.sort() on sub-arrays. Here is a demo program. Is this a bug in Java? package sorted_subsegments; import java.util.Arrays; public class sortTest { public static void main(String[] args) { …
SaSConsul
  • 298
  • 2
  • 9
-4
votes
2 answers

I stuck on read sub-arrays

I have an array with different first indexes. Now, I want to read all client_created strings without using $array[688]["client_created"], $array[690]["client_created"] ... How can I read all these client_created strings without using these numbers…
TheCodingBook
  • 21
  • 1
  • 7
-5
votes
1 answer

How to get subarray from mongo document?

How can I fetch a subarray from document? Here is one of documents: "director_details": { "0": { "AppointmentDate": "2010-06-02", "AppointmentStatus": "CURRENT", "AppointmentType": "SEC", "NumAppointments": "1", …
Mak Ashtekar
  • 154
  • 1
  • 11
-6
votes
1 answer

How can I sort subarray of objects

I have a array like in below code: [ { "items": [ { "name": "FRESH COCONUT WATER NAT PITCHER", "quantity": 50 }, { "name": "COVERS", "quantity": 10,}, { "name": "SPOONS", "quantity": 10,}, ], "report_id": 60594, …
1 2 3
28
29