Questions tagged [sub-array]

A sub-array is a subset of an array.

434 questions
-1
votes
3 answers

php array and sub-array

I`ve seen the following notation here: http://www.php.net/manual/en/features.http-auth.php What is ($users[$data['username']] for? Is it array and sub array? Would you please give me a clear example Thanks
Ayad Mfs
  • 33
  • 5
-2
votes
2 answers

Time Limit Exceeded Leetcode: How can I optimize my code in Javascript?

I am trying to solve the Two Sum II - Input Array Is Sorted 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…
Harsh Mishra
  • 862
  • 3
  • 15
  • 29
-2
votes
3 answers

I am trying to find out if there is a subarray, which has the sum exactly as K

I am trying find out if there is a subarray, which has the sum exactly as K. But in some its giving runtime error int sum = 0, count = 0; HashMap hm = new HashMap<>(); hm.put(0, 1); for (int i = 0; i < n; i++) { sum +=…
-2
votes
1 answer

How to reduce items in sub arrays based on the index?

examples: let a1 = [[1,2,3],[4,5,6]] //-> [5,7,9] let a2 = [[1,2,3],[4,5,6],[7,8,9]] //-> [12,15,18] let a3 = [[1,2,3,4],[2,3,4,5],[3,4,5,6],[4,5,6,7]] //-> [10,14,18,22] I thought I can do this easily but now I can't think straight anymore.…
roumen
  • 7
  • 1
  • 4
-2
votes
1 answer

Can't get this piece of code to pass. Can someone please help me

I don't know why this piece of code is not passing. Return true if each sub-list is individually in ascending order, false otherwise. public static boolean allSubListsAscending(ArrayList> list) { for (ArrayList
-2
votes
3 answers

How to find number of subarrays whose product is divisible by 4 in linear time

I tried but I am not able to correctly implement it. This is the code I wrote which is wrong as I am not counting some of the subarrays. Is it possible to write an algorithm which runs is O(n) int even=0 , count =0 ; for( int i=0 ; i
newbie
  • 5
  • 3
-2
votes
2 answers

Find subarray in integer array with least average in single loop

Given an integer array and size of subarray, find the first subarray with leat average in single loop. Print first index of subarray and average. Problem is I can't use variable substring length c without using any additional loop. My code…
-2
votes
1 answer

Maximum length subarray having sum greater than K

We want to find largest length subarray having sum greater than k. One of the solution that works is binary searching on the length of subarray. Length of subarray can vary from 1 to n. We can binary search in range low=1 to high=n and for every…
-2
votes
1 answer

Algorithm to find length of a minimal sub-array containing all the elements of an array/vector

Let's say we have an array {7, 3, 7, 3, 1, 3, 4, 1}. What I need is an algorithm (preferably some C++ code sample) which will return length of a minimal sub-array which contains all of the array's elements. In this case, it would be 5: {7, 3, 1, 3,…
anicicn
  • 183
  • 5
  • 15
-2
votes
4 answers

Dividing an array into two arrays

I have an array (rows) with n nodes. Each node contains 6 elements. Example: rows[0]: ["1", "Text", "0", "55", "0", "Text 2"] rows[1]: ["2", "Another Text", "15.5", "55", "16.6", "Another Text 2"] ... rows[n]: [...] I want to put the second element…
Alexander Vasilchuk
  • 155
  • 1
  • 1
  • 12
-2
votes
1 answer

how can i compare an array values with subarray values

I try to get the differences between two arrays I have one big array with subarray and a small simple array. I want to get the difference from the big array. I use this to get the differences between 2 arrays, but working with subarray is someting…
oxido
  • 1
  • 4
-2
votes
1 answer

Randomly subset vector in R

Is there a way to assign vector elements to multiple subarrays in R, using sample() or split() (or a combination of both functions)? Essentially what I need is a function that randomly assigns values to multiple subarrays Here's my full specific…
compbiostats
  • 909
  • 7
  • 22
-2
votes
1 answer

Push a string to an empty Array without it becoming a sub array

I have a sad array which consists of a string. var sadArray = ["I am a happy sentence."]; I would like to take this sentence out of the sad array (because its not a sad sentence :) ) and move it into the happy array var happyArray = []; This is the…
Sami Birnbaum
  • 773
  • 8
  • 20
-2
votes
2 answers

maximum sum subarray of window k algorithm not returning correctly for start index

Here is my code for maxSum subarray given input array -> [110,-4,3,6,7,11] and k =3, the code should give [110,-4,3] since that is the subarray which has maximum sum. I have implemented the algorithm. it works for all the input except one. I am…
brain storm
  • 30,124
  • 69
  • 225
  • 393
-2
votes
2 answers

count a continous subarray start with that index

I have a array A and want a array B of same size of A where B[i] represent length of continous subarray start with A[i] in which all elements are less than or equal to A[i] Example A={1,3,4,2,4,5,1,6} Output B={1,1,3,1,1,2,1,1} Explanation…
1 2 3
28
29