Skip to main content
1 vote
2 answers
98 views

How to get maximum average of subarray?

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
128 views

How do I create key-value pairs by looping over subarrays in Ruby?

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
91 views

How to optimize this code: Leetcode input was unexpectedly ( Memory Limit Exceeded )

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
65 views

Sum of comparisons and exchange between two sorting methods and their comparison (shell and quicksort)

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
43 views

Get Index of Sub Array in MongoDB

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

Maximum Count of Subarray having sum >= k and length >l

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
44 views

Why aren't large numbers working for this Ackerman Subarray Solution?

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
150 views

Sum of maximum element of all subarray not including the first and last element

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
31 views

compilation process in some java question about relate to 2d arrays

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
1k views

Efficient way to find sum of largest x elements in a subarray

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
  • 644
-2 votes
1 answer
65 views

why is it different to print statement within the inner loop and outside the inner loop?

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
88 views

Finding sums of all subarrays of an array

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
162 views

how this tricky problem could be solved in python for creating subarray

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
60 views

What are some efficient ways I can generate distinct halves of an integer array?

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
75 views

Issue with ArrayList array generation [closed]

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

15 30 50 per page
1
2 3 4 5
35