All Questions
20 questions
1
vote
2
answers
70
views
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],
...
0
votes
1
answer
141
views
How to search a matrix/array for a subarray containing a specific string (Javascript)
I have a matrix along the lines of this:
const chartypes = [
["bad boy","masc"],
["celebrity","neut"],
["activist","neut"],
[...
0
votes
0
answers
54
views
How to find length of longest continuous subarray such that first and last element are minimum and maximum?
How to find longest continuous subarray S[i..j] of array A[0..n-1] such that S[i] is minimal and S[j] is maximal element in S. It should be solved in O(N) or O(n log n).
-1
votes
3
answers
2k
views
Looping through array of arrays (subarray), column by column
Here i my array of subarrays
const array = [
[0, 1, 2, 3], // Loop from top to bottom?
[4, 5, 6, 7, 8, 9], // |
[10, 11, 12, 13, 14], // |
[15, 16, 17, 18, 19], // |
] ...
1
vote
1
answer
277
views
Shortest Unsorted Continuous Subarray: why do we start at the end of the array?
I have been wrestling with this problem for quite a bit:
Given an integer array nums, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole ...
0
votes
3
answers
94
views
Sort array elements on JavaScript
I have an array, each subarray of which contains different positions in different order:
[
["apple(2)", "banana(5)"],
["peach(3)", "banana(1)"],
["...
-6
votes
1
answer
72
views
How can I sort subarray of objects [duplicate]
I have a array like in below code:
[
{
"items": [
{ "name": "FRESH COCONUT WATER NAT PITCHER", "quantity": 50 },
{ "name": "...
1
vote
3
answers
1k
views
How to sort only part of array? between given indexes
I have an array of numbers and I need to sort only part of it by left and right barriers.
Can you please help me how to implement it correctly?
const sortBetween = (arr, left, right) => {
...
}
...
0
votes
2
answers
57
views
Recursive array listing catetegory
I have a multi-dimensional array:
Array
(
[0] => Array
(
[category_id] => 20
[category_name] => Category 1
[main_category] => 0
[sub_categories] => Array
...
0
votes
1
answer
2k
views
number of subarray with average greater than average of the rest of the elements of array
We are given a array of size < 2000
and A[i]< 10^6.I know the bruteforce approach.Can we do better i.e in linear time ?
I am checking each subarray and comparing its average with the other ...
1
vote
2
answers
91
views
PHP usort array based on subarray elements not working right - buggy?
Here's my current code, using php 7.1.20-1+ubuntu18.04.1+deb.sury.org+1:
(Four columns to sort by, 5th column just a subarray reference number.)
$dud = [[2,3,"2018-07-19","08:23",1],
[2,3,"2018-...
1
vote
1
answer
227
views
Sorting sub-arrays in Neo4j
I need to remove all duplicates from a set of arrays, but we define 'duplicate' in a special way here: Two 4 element arrays are 'dupes' if they share the first two elements in any order and the last ...
1
vote
4
answers
132
views
PHP - sort nth-level subarray
Let's suppose I've a nested PHP array $aaa where
the entry $aaa[$bbb][$ccc] is like
array(0 => array('x' => 3, 'y' => 2), 1 => array('x' => 2, 'y' => 1), 2 => array('x' => 4, '...
0
votes
2
answers
1k
views
find the minimum value of subarray kahn Academy
This Kahn Academy Question asks to find the minimum value in sub-array starting at the 2nd index, my algorithm is returning 4 but it hasn't prompted me saying that i am correct.
I am wondering where ...
-4
votes
1
answer
637
views
Problems with Java Arrays.sort() on sub-arrays -- is this a bug? [duplicate]
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 {...