# 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.

1,602 questions
Filter by
Sorted by
Tagged with
53 views

### Find the combination of matches which are closest to each other

Problem - Given three sorted arrays find combinations which are closest to each other. example - ...
40 views

### Best way to split array to two sub-arrays, with maximum absolute difference between them

Given array a, we want to find an index k in range [0, a.length-1] such that: ...
109 views

### A basic multi-dimensional array

I have been lurking on the C++ side of stack-overflow only long enough to know there are a lot of beginners and intermediate programmers baffled by multi-dimensional arrays. I've seen a lot of ...
67 views

### Median of two sorted arrays (optimal runtime) [closed]

I've written a solution to the leetcode problem Median of Two Sorted arrays. The solution I anticipated coming up with initially was going to features some kind of binary search on both arrays based ...
100 views

### Manipulating arrays to extract unique objects and count occurrences

The data describes cycling activities (key1) and chunks of them (key2). In total there are around 1,000 ...
556 views

### Array Interlacing

After I couldn't find any matching algorithm that would Interlace arrays I wrote this generic static function to combine arrays with variable segment sizes with n number of arrays. The theory of this ...
2k views

### MAXSPPROD linear algorithm

I am working on the MAXSPPROD problem on interviewBit You are given an array A containing N integers. The special product of each ith integer in this array is defined as the product of the ...
85 views

### Use arrays to perform 'VLookUp' type activity between workbooks

Background I have the below UDF that opens a workbook (this workbook has extracted data from a queue within another app). I get the used range from this workbook and assign it to an array (...
55 views

### Building an interval-based grid

I have an interesting problem to solve and despite having a running solution, I was wondering where I could improve it. In a range from 1 to 1000, I want to create an array with different increments ...
1k views

### Extracting a specific substring in C

I have a string like this: char buffer[] = "blablabla$GPTXT->SOME CODES HERE<-\r\n$GPRMCblablabla"; It is sent from an external device and changes every 1 ...
29 views

### Formatting data in array with objects

I am formatting a data result from the array of objects that looks like this: ...
2k 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 ...
212 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 ...
82 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, ...
32 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 ...
33 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 ...
46 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 ...
318 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? ...
749 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 ...
144 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 ...
71 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 ...
466 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 ...
842 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: ...
125 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 ...
190 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-...
202 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 ...
42 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 ...
126 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 ...
32 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 ...
467 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 ...
72 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 ...
73 views

### Sort multidimensional array based on another one containg the desired order

I have an array like this: ...
1k 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 ...
65 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: ...
22 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 ...
85 views

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

Let's say I have this pattern and a large array: ...
615 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? ...
224 views

### Random quote rotator

On my website, I created like this banner that rotates quotes from an array I made. ...
178 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 ...
130 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 ...
73 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. ...
114 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 ...
173 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 ...
112 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: ...
111 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. ...
139 views

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

I tried solving the Hash Tables: Ice Cream Parlor question in javascript: ...
67 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 ...
321 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 ...