Questions tagged [sub-array]

A sub-array is a subset of an array.

434 questions
1
vote
2 answers

Given and unsorted array arr , of size n of non-negative integers, find a continuous subarray which adds to number sum. Help in getting output

#include using namespace std; int main() { int n; n=4; int arr[n]={1,2,3,8}; int sum; sum=5; int curr=0; cin>>sum; for(int i=0;i
Diksha Nasa
  • 135
  • 3
  • 13
1
vote
1 answer

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 array will be sorted in ascending order. (cmp.…
1
vote
3 answers

Find if there is any subarray that do not match specified condition

I have an array called orgnisation. This array entails units in the organisation. Each unit is an object that has an array staff. Some staff have drivers license type A (driversLicenseA). checkDriversLicense function must go through organisation and…
1
vote
1 answer

How to get the number of the Subarray with at least K different numbers?

The question is: "Given an array A only contains integers Return the number of subarrays that contain at least k different numbers. Subarrays cannot be duplicated." Example: input array = {1, 2, 3, 4, 2} k = 3 output: 4 Explanation: the number of…
heheNhaha
  • 25
  • 1
  • 6
1
vote
1 answer

How do I reverse runs of nonnegative integers in an array in C?

I need to create a random array in C, find nonnegative values in it, and when there are at least 2 in a row, reverse them. For example, if I have the random array 5 6 -7 -8 9 -4 7 8 2 -2 I need to get 6 5 -7 -8 9 -4 2 8 7 -2. This is what I've tried…
Rexepo LT
  • 15
  • 4
1
vote
5 answers

JavaScript subarray Iteration

I want to capitalize the first letter of every word in a string. I want to know why this is not working: function titleCase(str) { str = str.toLowerCase().split(" "); for(let i = 0; i
Majd
  • 328
  • 4
  • 12
1
vote
1 answer

To return subarray as well alongside maximum sum of subarray using kadane's algorithm

This code of mine returns maximum sum of subarray using kadane's algorithm. What changes can i do to this code to return the subarray corresponding to the maximum sum as well ? def maxSubArray(a,size): curr_max=a[0] max_so_far=a[0] …
1
vote
1 answer

A method which finds the smallest subarray that's greater than X returns wrong number

For example, {1, 4, 45, 6, 0, 19} and the number 51 should return 3, because the number of elements in the smallest subarray which together are greater than 51 are 3: {4,45,6}`. {7, 2, 5, 10, 1} and the number 9 should return 1, because the number…
Ohande
  • 55
  • 5
1
vote
3 answers

PHP Array_unique

Is it possible to remove sub arrays, if the array item at position 0 of that sub array matches subsequent items? For example; Array ( [0] => Array ( [0] => 1234 [1] => XX000 ) [1] => Array ( [0] => 1234 [1] => XX001 ) [2] => Array…
user1235285
  • 87
  • 2
  • 17
1
vote
1 answer

Maxumum non-contigious subarray in Python

I have to fing an increasing non-contigious subarray with maximum sum using Python. For example, if I have an array [5, 2, 4, 3, 7, 7], than I have to output [2, 4, 7]. Output given is increasing, have the maximum sum among all the possible…
fiendfire28
  • 161
  • 2
  • 10
1
vote
1 answer

Maximum subarray Strawman algorithim time complexity enquiry

I recently came across a function called the strawman algorithm which the pseudo code looks like this: StrawmanSubarray(A): Initialize bestsum = A[0] For left=0 to n-1: For right = left to n-1: Compute sum A[left] + . . . +…
sctts-lol
  • 557
  • 5
  • 9
1
vote
1 answer

Hiding sub-array non-matching from mongodb gte seach

So I have been able to get my gte query to work for mongodb. However I have noticed that the query while yes correctly prints out the document. It does not remove/hide the subarray that are not correct. For…
RussellHarrower
  • 6,470
  • 21
  • 102
  • 204
1
vote
1 answer

How to ensure an atrribute is a subarray of another attribute in typescript?

I would like to create an interface where values of one array attribute can be only a subset of values of another array attribute. So it would work like this: interface Arrays { array: string[], subArray: ... // some type, string[] is not…
Václav Pruner
  • 310
  • 1
  • 11
1
vote
3 answers

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) => { ... } given: [9,3,5,7,4,9,4,1] , left = 2, right =…
1
vote
2 answers

Chunking an array by value with odds and evens

I'm trying to create a function that groups an array of numbers based on a length parameter. The length represents the max length of each sub-array. The code works as it is meant to for getting the sub arrays, but what I'd like to do is make it sort…
de19
  • 75
  • 8