Questions tagged [array]

An array is an ordered data structure consisting of a collection of elements (values or variables), each identified by one (single dimensional array, or vector) or multiple indexes.

Filter by
Sorted by
Tagged with
1
vote
0answers
26 views

Size out of limits in array made with malloc [on hold]

I'm applying what I learned in statistics class to a program to calculate everything automatically, but encountered an unexpected 'mistake' in my code. I say unexpected, because it's not the first ...
2
votes
2answers
112 views

Brute-force ID reversal search

EDIT The random number generator in this code is a blackbox for a similar algorithm that isn't publishable for privacy concern. The algorithm works in similar way, in that it takes in a seed value ...
3
votes
1answer
48 views

Simple winform that randomizes images in a picturebox

I wrote this code for a simple app that gives us random images. The code works, but I feel like I'm doing something wrong. And one thing I would love to know is instead of grabbing from a folder ...
-3
votes
0answers
40 views

Java ArrayList Sorting 2D ArrayList [closed]

I was trying to sort ArrayList including both Element but did not work great. ...
2
votes
0answers
42 views

Combining two nested for loops into one [closed]

Description What this does is it takes a randomly generated 64x64 stack and checks for overlap within the 64x64 array. Here is an example: https://imgur.com/a/kkPRzhn. Each color is its own ...
1
vote
1answer
86 views

Way to check if a byte array contains another byte Array

I'm checking if an byte array contains a another Byte Array with this Code: ...
3
votes
4answers
181 views

Java creating augmented array of size 400,000,000

I was solving one competitive coding question having integer bounds 2^100. Fortunately, it was a dp question and I didn't need an array of that size. Practically we ...
2
votes
1answer
45 views

Given an array, find all its elements that can become a leader, after increasing by 1 all of the numbers in some segment of a given length

I was successful in solving a challenge in codility, but my solution failed performance tests. How can I improve my solution? Challenge: Integers K, M and a non-empty array A consisting of N ...
1
vote
0answers
38 views

Codility's GenomicRangeQuery solution in C#

I've been learning C# for a few months now, and I've done some basic things in java last year. I made a solution for the problem the title states, this is the task description. Task description ...
1
vote
2answers
73 views

LeetCode: Spiral Matrix II C#

https://leetcode.com/problems/spiral-matrix-ii/ Please review for performance, how can this code run faster Given a positive integer n, generate a square matrix filled with elements from 1 to n^2 ...
2
votes
1answer
54 views

Codility's count passing cars in opposite directions in C#

I programmed a few things in java and now I'm learning C#. I've been doing exercises from Codility. The first 3 or 4 were very difficult to me but now I guess I've got the hang of it. This site ...
5
votes
2answers
141 views

MaxCounters solution in C# from Codility

I programmed a little in java a while back, and now I'm learning C#.This is the first exercise of "medium" or "respectable" difficulty according to Codility, so I'm pretty pleased of finding out that ...
9
votes
1answer
231 views

Earliest time frog can jump to the other side of a river in C#. Codility's task

I'm new to C#, I programmed a little in java in the past.I had the two previous exercises reviewed here (permCheck, cyclicRotation, with a 100% score, just like this one), and I'm applying what the ...
3
votes
1answer
59 views

Ring buffer with random access

I had an application where I really wanted a double-ended queue that supports random access. Java's ArrayDeque would have been perfect, except that it doesn't ...
6
votes
2answers
170 views

Codility's Permutation Check in C#

I've made a few things in Java, and now I'm learning C#. The code passes the tests with 100% final score. I want to know what things can be improved in my code. Task description A non-empty ...
4
votes
1answer
62 views

Maximum sub-array sum

My code finds the maximum subarray sum and the starting and ending index of that subarray. ...
2
votes
0answers
53 views

LeetCode: House Robber II C#

https://leetcode.com/problems/house-robber-ii/ You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place ...
2
votes
1answer
52 views

Codility Cyclic rotation in C#

I'm learning C#, I programmed some things in java, and I would like to have a feedback on my C# code. The exercise is from codility. The goal is to rotate array ...
2
votes
1answer
76 views

transform list to array

Q: Write a method that transforms a list into an array (don't use collections or already implemented methods in lists, make your own method) I've come with this solution: ...
1
vote
0answers
36 views

Stochastic gradient descent - backpropagation over mini-batches in one go

I have been working through a tutorial on neural networks. I have then been translating the code to java, to help improve my understanding of what the code is doing. The book mentions a way of ...
4
votes
2answers
104 views

An ES6 array of numbers - Double last number, delete the first number

I'm writing a JavaScript function for an array, based on a geographic sequence. \$[1, 2, 4, 8, 16]\$, etc. This function needs to populate the next number in the sequence $$item_n = item_{n-1} * ...
1
vote
2answers
110 views

Merge k sorted lists in Java

I hava a question similiar with mege in Python but I am trying to write Java code. Here is my code: The input is: The first line - a number of arrays (k); Each next line - the first number is the ...
4
votes
2answers
63 views

Breakout clone in pygame

As a guy who started coding a month ago, I would like an honest review of my version of breakout that I created using pygame. ...
1
vote
1answer
37 views

Activity Selection to maximize the number of activity executions

I solved this problem from a challenge.The problem is as below:- Problem Statement: Given N activities with their start and finish times. Select the maximum number of activities that can be ...
6
votes
1answer
194 views

Excel's Dynamic Array Functions…In VBA (No Win 32)

In recent months I have been trying to figure out how in the world one can mimic the functionality of Excel's New Dynamic Arrays exclusively in ...
6
votes
2answers
958 views

Count the frequency of items in an array

The question is: Write a program that prompts the user to input ten values between 80 and 85 and stores them in an array. Your program must be able to count the frequency of each value appears in ...
5
votes
2answers
490 views

Partitioning and sorting even and odd numbers within an array

I solved a problem where it was told to sort an array of numbers such that the even numbers are kept first and the odd numbers should follow. Moreover, the even numbers must be sorted in ascending ...
3
votes
1answer
85 views

Summing same index values in 2D arrays in javascript

After solving a problem, I came to this conclusion. ...
3
votes
2answers
49 views

JavaScript number obfuscater

I got inspired to do this after seeing this repo containing a bunch of weird syntactical quirks in JS, namely this example called "It's a fail!". The example was essentially the following: You ...
8
votes
1answer
151 views

An array with \$O(\log\ n)\$ time complexity for all operations

Does this exist already? It's an array (=variable-size list with integer indices) where add/remove/set and get all take \$O(\log\ n)\$ time. I couldn't find this anywhere, so I made up the name "Log-...
3
votes
2answers
102 views

Minimum Number of swaps required to group all ones together in array of 0s and 1s

Problem Statement: Given a binary array data, return the minimum number of swaps required to group all 1’s present in the array together in any place in the array. ...
1
vote
1answer
58 views

Adding a number to an array of digits

I'm a student in my first semester and in my free time and holidays, I do some java training to keep my mind from rusting...so I downloaded this amazing Digital Algorithms practice app and came across ...
-1
votes
2answers
130 views

Union of two double arrays

I would like to merge two double arrays and remove from the result array approximately equal items. My two input arrays have ...
3
votes
2answers
50 views

Dynamic Array implementation in Python

I am trying to learn data structures by taking this Udemy Course, Easy to Advanced Data Structures by William Fiset. The course provided an implementation of Dynamic Array in Java. To ensure I fully ...
6
votes
4answers
3k views

Create two random teams from a list of players

The task is to create two random teams from a list of players. Given an example of players = ["John", "Mike", "Alice", "Bob"] One example random team would be: <...
4
votes
2answers
47 views

Extract lines under the specified heading

I wrote the following working code, which I just can't stomach: ...
-2
votes
1answer
59 views

Challenge - Construct binary tree from array [closed]

A coding challenge to construct a binary tree from an array. ...
3
votes
2answers
91 views

Algorithm in getting total garnered hours for student using php

Hello I'm calculating now the total garnered hours student get in school using php. (Same concept in getting the total work hours in employee for timesheets) So I have an array $attendance where the ...
2
votes
1answer
73 views

Fast “index of minimum” for distances to points on single thread

The problem in simple words: I have three arrays of double values (x-, y- and z-coordinates) and need to find the index of the point which has minimum distance to a reference points. I do not need the ...
3
votes
2answers
136 views

Finding unpaired number in an odd Array of integers

A non-empty array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be paired with another element that has the same value, except ...
7
votes
5answers
1k views

Finding all possible pairs of square numbers in an array

I am writing a program that allows me to find all possible pairs of square numbers including duplicates. We can also assume the array elements to be of positive integers only. e.g an array of {5,25,3,...
4
votes
2answers
77 views

Array of all permutations in C

Is this a good compromise between readability and verbosity? Are there any bugs, additional error checking, or extraneous code as well? ...
2
votes
2answers
68 views

Filter list items

I have a list of items I pull from SharePoint and want to filter them in my custom list view page. So my function works exactly how I want, but it seems messy and I'm hoping someone could point me to ...
2
votes
3answers
68 views

PHP recreate array if it contains certain values

I have $fruits_arr: ...
2
votes
2answers
104 views

Counting Valleys - HackerRank Challenge

For this challenge on HackerRank: A valley is a sequence of consecutive steps below sea level, starting with a step down from sea level and ending with a step up to sea level. Given Gary's ...
8
votes
5answers
2k views

Find The One Element In An Array That is Different From The Others

https://www.codewars.com/kata/find-the-stray-number/train/javascript I solved this challenge by sorting from least to greatest, and checking if the first element in the array matched the second ...
0
votes
0answers
107 views

Minimum sum of elements, taken 2 at a time

Update: I had not recalled the question correctly and ended up with the wrong question. I have now updated the question and the solution: The question is: Given an array of integers say [8,4,6,12,10] ...
2
votes
1answer
117 views

A heap-allocated texture class for a console renderer

I am working on a console renderer and I want a heap-allocated dynamic texture class. Since I am quite new to C++, I just want to check the memory management, if I destroy all pointers correctly etc. ...
1
vote
3answers
91 views

PHP - check if array includes value and return value if true

I developed the function array_includes which checks if an array contains a value and returns it. I would like to know if there is already such a function which is ...
2
votes
1answer
108 views

Union, Intersection and Diff of two sorted arrays in C#

This is the original question https://www.geeksforgeeks.org/union-and-intersection-of-two-sorted-arrays-2/ Given two sorted arrays, find their union and intersection. ...