Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
0answers
16 views

Formatting data in array with objects

I am formatting a data result from the array of objects that looks like this: ...
1
vote
1answer
40 views

Passing shared memory array to worker pool in Python

I'm working with big 2d numpy arrays, and a function that I need to iterate over each row of these arrays. To speed things up, I've implemented parallel processing ...
0
votes
0answers
39 views

Static bounds tensor

Basic tensor class with static bounds. I want to get this done properly, because plan on using this on the GPU in the future. This also means I cant use any STL containers. Speed is pretty important. ...
1
vote
1answer
62 views

Tic tac toe game using C++

I wrote this C++ code for Tic-tac-toe for an interview (The basic skeleton was pre-provided) and got rejected because the code was too complex and inefficient. I'm not an expert programmer so I'd like ...
2
votes
0answers
40 views

x64 Windows Assembly - Structs in Assembly

I'm trying to code a simple person database using structs and arrays in assembly. Each person has a firstName, lastName, ...
0
votes
0answers
24 views

Find target in sorted array pivoted at some unknown point in O(log n)

You are given an array sorted in ascending order which is rotated at some pivot unknown to you beforehand. Find your target in O(log n) which means it should be a binary search. If the value does not ...
1
vote
0answers
23 views

Drawing sprites and adding new ones

I have some code that draws sprites and and allows new ones to be added. To do this, I use 2 lists: 1 for the sprites that need to be drawn, and one for the new sprites that need to be added to the ...
1
vote
1answer
33 views

Centre all columns of an array

I have this working code tested over lots of np.arrays. It is a for-loop that walks through all the values of a np.array (x,y). For each y-row, it finds the first x-column for which the value is ...
0
votes
0answers
38 views

Dynamic Array Queue Implementation

I implement a Queue with resizable array, but i have a question about it... we are adding elements to our array, but when we delete them, do we need to leave the first element - example arr[0/head] ...
2
votes
2answers
59 views

Simple implementation of LRU caching in PHP

This is my implementation of LRU caching in PHP. It works fine when I tested as. What are the things that I miss or need attention? ...
3
votes
2answers
80 views

Swapping pairs of characters in a String

Question: Write a program to swap pairs of characters of a String. In case of odd number of characters last character should remain unchanged. Examples: Input: HI Output: IH ...
3
votes
1answer
62 views

Count contiguous sub-array whose sum is a perfect square

I have to count the number of contiguous sub-arrays whose sum is a perfect square. For instance, if we have an array: number = [1,4,2,3,5] Now the contiguous ...
2
votes
2answers
55 views

Initializing a tile-like map such that the edges are marked with an 'X'

I've been messing around with arrays as I'm learning them currently in my book and they gave the idea of a chess board using for loops alongside multidimensional arrays to give them individual values ...
-2
votes
0answers
49 views

Alternatives to placing all the data in memory while parsing large files

Recently, I had a situation where I had a log file and had to come up with some data from that file. That file contained the trace of a piece of code starting and the ending along with some common ...
8
votes
4answers
443 views

Performing a “mean blur”

I perform a mean blur on a number[][]-array (called grid in the code). I iterate the array, and calculate average values from ...
1
vote
1answer
71 views

Find sum of all the subarrays of an array

I have an array. Now I want to find the total of, sum of the subarray multiplied by its last element, for all the possible subarrays. This is what I have right now: ...
2
votes
2answers
89 views

Index Match implementation

The code below takes header variables, retrieves the column index, and then, using an Index/Match function, returns data from a matching account number. The reason it is written this way is because I ...
1
vote
1answer
76 views

Odd Even Subarrays

I've been trying to understand Dynamic Programming lately, here's the question I just attempted: You are given an array A of N positive integer values. A subarray of this array is called an Odd-...
0
votes
1answer
65 views

Determine whether any permutation of a given array exists such that the sum of all subarrays of length K are equal

I was asked this question in an interview. You are given an array consisting of N integers. You need to determine whether any permutation of a given array exists such that the sum of all ...
1
vote
0answers
28 views

Merging and summing multi-dimensional arrays

I've found myself today really struggling with this subject and I'm pretty sure that there must be a better way to do this. First of all my arrays have the same layout, I need to merge them and sum ...
1
vote
0answers
31 views

Getting all unique permutations from a slice of integers slices in golang,

For a project I'm working on I have a set of number sets, and I need all unique permutations of them. I want to return only one copy of each unique number set, and I'm struggling to figure out how ...
1
vote
0answers
26 views

Converting an array of users into an array of teams with an array property for listing the users

Jst to clarify, teams and groups are the same thing in this case. $data comes from a database and is an array of objects. Each object contains information about a ...
2
votes
1answer
98 views

Swift - Finding longest binary gap of a given integer

I recently had the chance to try Codility's algorithm training, and the very first one in the list is finding the longest binary gap of a given integer. I tried to implement this in Swift, and after ...
0
votes
2answers
62 views

ContactsList implementation in Java

I created a ContactsList class in Java that holds Person objects. I consider this is a side project for my GitHub profile. Any ...
2
votes
4answers
70 views
1
vote
2answers
76 views

Javascript: Canvas drawing - storing mouse coordinates

I have a small JS application that allows a user, after clicking on a canvas, to draw a picture. Once the user clicks the mouse, the user is allowed to drag the mouse wherever they want within the ...
0
votes
1answer
48 views

A simple linked list of arrays in Java

Introduction This simple data structure combines ArrayList with LinkedList. In other words, it is a linked list of arrays: ...
0
votes
0answers
15 views

Processing object writes to external datastore in parallel using ForkJoinPool and list streams

I have the following code. I wanted to see if you thought this was a good way to go about processing an array of objects in parallel using a ForkJoinPool and array streams. This is just a sample, in ...
2
votes
2answers
78 views

Check if specific pattern exists in another array and save the index

Let's say I have this pattern and a large array: ...
0
votes
1answer
104 views

Median of two sorted arrays

The task is to find the median of two Arrays. I have an O(n) solution. Can it be written in a better time complexity? ...
6
votes
2answers
193 views

Random quote rotator

On my website, I created like this banner that rotates quotes from an array I made. ...
3
votes
1answer
88 views

Array Partitioning

I have a method in Java that I'm using to partition byte[] arrays into a number of fixed-size sub-arrays. It's not necessary for the last array to be that size, but all preceding ones must be, and the ...
4
votes
1answer
123 views

“What To Do” App

I am starting to build up my portfolio, so I am starting to build projects whenever an idea pops up in my head. So, I decided to build an app that helps you decide what to do. Basically how it works ...
3
votes
2answers
64 views

A Stack Implementation In C

I've written a very simple linked list based stack implementation and was wondering if this is the standard way to do it in C. ...
4
votes
2answers
105 views

Minimum difference between numbers in a file

I'm learning Java and I created a simple solution for the following problem: Given a file [filename].txt such that each line has the format ...
0
votes
0answers
40 views

Identifying objects as some type of enum

Please review my code. It works as it should but I think about making it more pretty or optimal. This method should take in some IEnumerable of ...
2
votes
0answers
38 views

Drawing an ASCII grid in Ruby based on a 2D array

I'm writing a function that renders a grid using ASCII line-drawing characters, based on a provided 2D array (or array of arrays), with each top-level array representing a row, and the items inside ...
4
votes
2answers
64 views

Checking if an array can be rotated to equal another in JavaScript

I needed to write a function in JavaScript which checks if any rotation of an array is equal to another array. By rotation, I mean: ...
4
votes
2answers
105 views

Finding the second largest value In an Array

findSecondLargestNumberInTheArray() method returns the second highest number from an array. Could you please review this code to enhance performance. ...
0
votes
1answer
45 views

Hash Tables: Ice Cream Parlor solution in javascript [closed]

I tried solving the Hash Tables: Ice Cream Parlor question in javascript: ...
3
votes
1answer
54 views

Getting angle between all points in array

I have got some code that calculates the angle between all of the points in an array. It works, but it is quite slow. This is because it has complexity O(n^2). It has to loop through the array and ...
7
votes
1answer
222 views

Calculating the number of rooms in a 2D house

I stumbled upon this problem on cses.fi (a problem set for the Finnish Olympiad in Informatics. This problem is in finnish so I'll translate it). I'll describe the problem, present the code and think ...
4
votes
4answers
92 views

Filtering a name Array in JavaScript

I was wondering if there is a better, more elegant way to write the following JavaScript code block: ...
3
votes
1answer
54 views

Counting sort in C, revised

This is a revised follow-up to this question. I have implemented most of the suggestions in the accepted answer. I am interested to see what I could improve in my code and what I could do to make it ...
0
votes
1answer
66 views

Counting contiguous subarrays with a negative sum

I'm doing a coding challenge that asks to count the number of contiguous subarrays that have a negative sum: A subarray of an n-element array is an array composed from a contiguous block of the ...
2
votes
1answer
31 views

Generating random N-dimensional arrays

For this code challenge, I want to create a performant function that creates a rectangular N-dimensional array. (min_dim_size, max_dim_size) is the span size of every dimension. So ...
2
votes
2answers
32 views

Algorithm that parses through input of points and finds distance

I'm wondering if someone could take some time to review this script. I'm parsing through a list of points of any length and calculating the distance. I'm wondering how to make my code better/more ...
5
votes
4answers
509 views

Summed absolute difference of two array

Question (SAD Queries on CodeChef) The Summed Absolute Difference (SAD) of two arrays. Given arrays (1-indexed) \$P\$ and \$Q\$ of lengths \$p\$ and \$q\$. Given a collection of \$n\$ arrays ...
1
vote
1answer
50 views

Possible letter combinations of a dial pad in linear time using a recursive approach

Time complexity: I walk the initial unzipped array of keys representing the number O(N) backwards. I then do an inner walk of the proceeding array of letters *O(L^2), mapping it to every value in the ...
1
vote
3answers
83 views

Find value that occurs in odd number of elements

I am trying to solve the following exercise using Javascript: 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 ...