Skip to main content
Filter by
Sorted by
Tagged with
3 votes
2 answers
199 views

The method is working as intended, but while I was trying multiple cases, I got this weird issue, so hopefully someone can understand why and explain it to me, since 6 > 5 looks logically sound to ...
chtasmino's user avatar
1 vote
2 answers
155 views

I have been working this leet code questions https://leetcode.com/problems/maximum-average-subarray-i/description/ I have been able to create a solution after understanding the sliding window ...
Zubair Amjad's user avatar
1 vote
2 answers
136 views

I'm trying to write a Ruby program which will parse the following TSV file and loop over each record, adding each shop name (last column) as the key in a hash and the associated price (second column) ...
green_ruby's user avatar
0 votes
1 answer
132 views

Leetcode question: Given a binary array nums, return the maximum length of a contiguous subarray with an equal number of 0 and 1. Leetcode entered a very long input of to the function and its IDE ...
TheWalrus's user avatar
1 vote
0 answers
67 views

I'm trying to make a code that counts Shell and Merge comparisons and swaps, making a sum between the sum of the comps and swaps. The vectors are a subArray, such that, given: 4 (line break here) 3 6 ...
Poueeerr's user avatar
-1 votes
1 answer
49 views

I have the following array: const universitiesSchema = new Schema({ name: { type: String, required: [true, 'Required'] }, users: { type:[Schema.Types.ObjectId], } }); I would ...
spongebob89's user avatar
0 votes
0 answers
21 views

For a given array we need to find the maximum number of subarrays possible. Conditions: 1.The sum of each subarray should be >= minSum 2.The length of the subarray should be >= minLen We need to ...
Ashish Lakhmani's user avatar
0 votes
1 answer
53 views

You are given two inputs for this program; <the_number> <checking_number> For every sub-"array" you have, you need to sum up the digits of that sub-"array" and check if ...
mxchi16's user avatar
1 vote
3 answers
170 views

I am trying to make an algorithm that calculates the sum of each maximum element in a subarray not including the first and last elements. The naive approach is obvious but I do not want that. Here is ...
user avatar
0 votes
1 answer
36 views

public static boolean ContainedArr(boolean[][] photo, boolean[][] sub) { //find if sub is sub array in photo if (sub.length>photo.length ||sub[0].length>photo[0].length) { //sub bigger ...
Itamar B-E's user avatar
20 votes
3 answers
2k views

I have a 1-indexed array of positive integers, and I want to make several queries to it, all in the form, 'what is the sum of the largest x integers in the subarray 1 to y inclusive?' This array is ...
Redz's user avatar
  • 784
-2 votes
1 answer
66 views

I was asked to print the number of negative subarrays. I used three loops to fix a starting position, ending position and a loop to print elements of subarray. I need to use count to check if the sum ...
Kowshika's user avatar
0 votes
0 answers
89 views

This is a snippet from this code to finding sums of all subarrays of a given array, but this doesn't work as intended as the problem seems to be lying with pre-incrementing value of i in the equation. ...
Pradyuman Sharma's user avatar
-5 votes
1 answer
165 views

write a program to create subset of given array the value inside the array should be target value and length of array should be k program that i have tried arr = [1, 2, 8, 6, 4, 9, 5] k = 3 target = ...
6004 Abdul Rahman Harris's user avatar
-4 votes
1 answer
66 views

Given an integer array, I want to print out all the distinct pairs of halves of the array. [2,1] [3,2] and [3,2] [2,1] can be considered distinct. I'm sure there's a brute force way, but I want ...
Eggy's user avatar
  • 1
-2 votes
2 answers
83 views

You are given an array A of N integers. Return a 2D array consisting of all the subarrays of the array. I had tried to get subarrays in temp as per loop and add that subarray directly to ans(2d ...
Shubham Kumar Singh's user avatar
1 vote
3 answers
103 views

I have an array: > a array([[[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], ...
Jun's user avatar
  • 55
-1 votes
1 answer
54 views

I have the following array,in which, I have an item 'CONSECUTIVO_GRUPO', which I want to take as a reference to create a group of 'RESPONSES' in an array of three positions, CODIGO, ID_MODULO, VALOR. ...
AlJw's user avatar
  • 71
1 vote
3 answers
69 views

I have an array: > a array([[1, 2, 3], [2, 3, 4], [3, 4, 5]]) I want to change those values to the avarage of those values, so the output will be: > a array([[2, 2, 2], [3, 3, 3], [4, 4, 4]]) ...
Jun's user avatar
  • 55
0 votes
4 answers
2k views

Question: You are given an integer array nums consisting of n elements, and an integer k.Find a contiguous subarray whose length is equal to k that has the maximum average value and return this value....
Gargi 's user avatar
1 vote
0 answers
369 views

How can I find the number of subarrays where bitwise XOR of the element of the subarray has odd number of set bits. Basically I need to find the solution in linear time. I could solve in O(N^2). What ...
Snehasish Bhakat's user avatar
1 vote
3 answers
921 views

I have two Python arrays with arrays inside: first = [[0,10],[0,11],[0,12],[0,13]] second = [[0,10],[0,11]] and I want to get as a result the array that is in the first one, but not in the other: ...
BSDash's user avatar
  • 13
0 votes
1 answer
392 views

I want to do a sub-array selection Python-like (ArraySlice) in Swift. This is working for me, but I know it's not nice. To make it work I used .suffix embedded to .prefix method. I'm wondering if ...
ccmsd18's user avatar
  • 58
1 vote
2 answers
504 views

For the question below: Given an array A of N non-negative numbers and a non-negative number B,you need to find the number of subarrays in A with a sum less than B. I have found 2 solutions: Brute ...
Ashy Ashcsi's user avatar
  • 1,599
0 votes
1 answer
285 views

I am trying to create a continuous subArray from a given array which is equal to the given sum and return the first and last index as an ArrayList. This is the solution i could think of which actually ...
Sourav Borah's user avatar
0 votes
0 answers
430 views

I have an array of N integers, and I have to find the number of such segments that they contain within themselves segments whose cumulative sum is equal to zero. For example, if I have an array [5, -5,...
annflames's user avatar
1 vote
1 answer
162 views

I need to find a performant and smart way to redesign the formula or the tables on which it depends (COSTO_DUMMY and GG_TARGET). Can you help me, please? I can add new support tables if needed ...
Franco's user avatar
  • 87
0 votes
1 answer
346 views

In the following array how can the object with "step":"2" be removed from the sub-array "subGroupB" only when "code":"code-333"? { "mainGroup&...
HobieKatz's user avatar
-3 votes
2 answers
557 views

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's user avatar
  • 1
-1 votes
2 answers
122 views

I am studying algorithms in JavaScript; I am trying to generate consecutive subarrays but I don't know to do it. I have the following array: [1, 2, 3, 4, 5, 6, 7, 8, 9] I want to split it in ...
Kerpen rodrigo rosa de miranda's user avatar
0 votes
2 answers
92 views

public class maxsubarraysum { public static void main(String[] args) { int numbers[] = { 1, -2, 6, -1, 3 }; printmsasum(numbers); } public static void printmsasum(int ...
Sarthak Parmar's user avatar
1 vote
1 answer
520 views

I'm writing a Connect Four script. The script takes a list of moves as input ("A_Red, "B_Yellow", "G_Red", etc), which I'm sorting into a matrix. Each nested list represents a ...
CunnyFunt's user avatar
  • 105
0 votes
1 answer
693 views

Can someone help me with this. My code is working fine but consider a case of [-2,-1]. Since my maxSum is set to 0. My output is coming 0 instead of-1. How should I modify my code? Sample i/o: Input: ...
Shreyansh's user avatar
3 votes
0 answers
135 views

There is an array of numbers between 0 and 6 (base 7). For example {0 4 6 2 2 0 3 1}. Its maximum length can be 501 elements. Each step we can subtract a number from any number of elements. All of the ...
Altrey's user avatar
  • 31
0 votes
1 answer
990 views

Given an integer array sequence a_n of length N, cut the sequence into several parts such that every one of which is a consequtive subsequence of the original sequence. Every part must satisfy the ...
Sharhad's user avatar
  • 83
6 votes
1 answer
573 views

I noticed that taking views of non-"fast linear indexed" subarray allocates, while this is possible on classical vectors. Any idea, how to make this allocation free? Here is an illustration ...
Tanj's user avatar
  • 467
0 votes
0 answers
118 views

This is my code and it does well for positive numbers given in the array but when one of the input numbers is negative it doesn't work #include <stdio.h> int main() { int n; scanf(&...
ArianMohseni's user avatar
1 vote
2 answers
75 views

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], ...
Chris Ediger's user avatar
0 votes
1 answer
88 views

Hey there i have an numpy array y with over 4000 values. data=pd.read_csv('samplesdata.csv',sep=";", decimal=",",encoding='latin-1') sensor_data=data[['Euklidische Norm']] ...
Papadopolous's user avatar
0 votes
0 answers
32 views

I implemented a solution that uses xor to know if a product has been computed before. It recursively gets all the possible products. Here's the code: #include <stdio.h> int driver(int *arr, int ...
FariyaAchhab's user avatar
-3 votes
1 answer
197 views

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 ...
j.j.3's user avatar
  • 35
1 vote
3 answers
3k views

How to generate all subarrays from an initial array? Let's consider an array: [1,1,1,1]. I would like to generate all possible subarrays (in no particular order). Expected result: [1], [1], [1], [1], ...
PatPanda's user avatar
  • 5,428
0 votes
0 answers
115 views

Is there a function or more concise notation to get b or bb in the code snippet below? import numpy as np a = np.arange(12).reshape(3, 4) c = (1, 2) r = 1 b = a[c[0]-r:c[0]+r, c[1]-r:c[1]+r] bb = a[c[...
Paul Jurczak's user avatar
  • 8,628
0 votes
1 answer
144 views

I have a matrix along the lines of this: const chartypes = [ ["bad boy","masc"], ["celebrity","neut"], ["activist","neut"], [...
corvidia's user avatar
0 votes
1 answer
446 views

Let's say you have given an array of size N, which can have a positive and a negative number. we need to return the length of the largest subarray of sum equal to k. I tried to use the sliding window ...
Anurag Tripathi's user avatar
0 votes
1 answer
185 views

How to print the sum of user desired subarray from a given list [1,2,3,4,5,6] using slice method in python ? I've got success till the slice method and displaying the subarray , but I am not able to ...
Kake_000's user avatar
-1 votes
1 answer
58 views

This is my current code for a program to find the maximum subarray. I am getting the out of bounds error for 3 lines: I'm getting the error ArrayIndexOutOfBoundsException: index -25 out of bonds for ...
Tiffany 's user avatar
0 votes
0 answers
122 views

I have multiple dbf files in a directory that I am trying to loop through and convert into excel files. However, because the loop times out after running for a while I divided the array list into ten ...
Jay Antonio Oliver's user avatar
0 votes
1 answer
616 views

question given an array of elements 0, 1, 2 with find the total number of subarrays with the ratio of 0's and 1's equal to x:y. input 5 1 1 0 1 2 0 1 output 6 \\5 is the size of array 0 1 2 0 1 ...
Abhinav's user avatar
0 votes
1 answer
375 views

I was interested in finding a solution to a problem that provided a binary array called nums - which, for example, could consist of 10101, or 00000, or any such combination of 0 and 1's - from this, ...
Ramkrishna Sharma's user avatar

1
2 3 4 5
11