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.

1
vote
0answers
38 views

Project Euler #81 in Haskell: minimal path sum through a matrix

I just completed Project Euler Problem 81 in Haskell: In the 5 by 5 matrix below, ...
2
votes
2answers
35 views

I/O-TxtFile Line Distance Program

I am trying to write a lab/program that loops through a .txt input file. Reads an entire line of data as a string, then splits that string into an array delimited by a space. If there are 4 items in ...
1
vote
2answers
59 views

Printing elements of an array in C

I'm trying to print the elements of an array in a fashion that resembles thism where SIZE is a constant: ...
3
votes
1answer
72 views

List of word to list of index in a vocabulary [closed]

I have a dataset composed of ~700k samples. Each sample is composed of n_features features. Each feature is a word. Each feature has his own vocabulary. The size of the vocabularies range from 18 to ...
1
vote
1answer
23 views

Longest Substring Without Repeating Characters in Scala

Question is taken from Leetcode and solution works for their test cases. I do see a scope of improvement and make it more functional (getting rid of vars and mutables data structures). Please suggest ...
4
votes
1answer
85 views

Finding decreasing sequences in an array of numbers

Ants Requirement Given a natural number \$n\$, representing the number of days the study is made, and then a number \$x\$ of \$n\$ natural numbers, representing the number of working ant ...
1
vote
1answer
36 views

Get the most frequent number and least frequent duplicate in array

This code gets the most frequent number and least duplicate number in an array. How can I optimize it and improve its performance? ...
3
votes
1answer
57 views

Checking whether given array is sorted by divide-and-conquer

I've written a code that I try to use divide and conquer approach to determine if the given array is sorted. I wonder whether I apply the approach accurately. ...
-2
votes
1answer
43 views

Append to array if not empty [closed]

I want to call a series of functions to build up an array, like so: ...
0
votes
0answers
16 views

PHP - Optimise code that does a reconciliation between two arrays based on numerous fields

I build two arrays (I can't use SQL for this as I am using ROQL qhich only allows for very basic SELECT statements as shown) from a SQL query. I then want to see if any row matches in Array B based ...
-4
votes
1answer
79 views

Bidirectional bubble sort using goto [closed]

I am aware of Dijkstra's paper on why goto is harmful, but I thought it would still be fun to make a bidirectional bubble sort using ...
1
vote
2answers
49 views

A scalable way to remove duplicates from Arrays without extensions in Swift 4

This method is an attempt at removing duplicates from arrays with scalability in mind in Swift 4 without the use of extensions. I am asking for any suggestions, criticisms, and/or observations. ...
1
vote
1answer
46 views

Recursive trim() function to handle arrays and objects

I have come up with a recursive function which applies trim() recursively to all string members of an array/object. I don't have any specific quandaries about my ...
0
votes
0answers
59 views

Using nested multiprocessing pools in python

I'm processing image files, which are represented as 2d numpy arrays in python, and I need to iterate over the row of each array to apply a function. This is a ...
1
vote
1answer
52 views

Check if list contains a pair which adds up to a given sum

Kindly review this scala code for given problem and suggest improvements. Problem - Given an array of integers and a target sum, check if array contains a pair which adds up to sum. Example - <...
8
votes
2answers
201 views

std::array implementation

I'm creating my own implementation of the STL, compliant with the C++17 standard. The only purposeful differences are that the namespace is hsl (homebrew standard ...
0
votes
1answer
58 views

Checking if an array element exists in a JS object

I have a feature in my application that should allow users to select items in a drop down menu and move them up and down. Once they select and click on the button I have to loop over the array of ...
1
vote
1answer
42 views

Add Strings in-between index of ArrayList if not already exists

So as the title states, I am trying to add a specific Items to an ArrayList if they not already exist. So here is how the Array starts. [a, b, c, d, e, f] I have ...
5
votes
3answers
415 views

Count sub-sequences of an array having median lying in that subsequence itself

We need to calculate the number of sub-sequences of an array having its median lying in the sub-sequence itself. My code is - ...
2
votes
2answers
49 views

Printing a K-ary tree stored in level-order in an array

I am given an array that represents a k-ary tree (I am also given the branching factor "k") that is stored in level order. My task was to print the tree in level order. For example a trinary tree ...
0
votes
2answers
52 views

Convert HTML input string to JavaScript Array literal

I am trying to accept JavaScript array literals in an HTML text input. The problem is that HTML text inputs are captured as strings, such that an input of ...
3
votes
1answer
79 views

Effective 3d array transposition with R/C++ (Rcpp)

Task is reshape 3d array from [row, col, slice] to [slice,row,col]. I tried implement base::aperm analog with Rcpp. ...
1
vote
1answer
21 views

Combine contiguous spreadsheet cell references into larger ranges

For a hobby project, I am using openpyxl to export Excel workbooks as JSON. Part of this involves identifying the formatting applied to cells, and serializing this information (provided the format is ...
0
votes
1answer
41 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 - ...
1
vote
1answer
34 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: ...
1
vote
0answers
53 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 ...
0
votes
1answer
39 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 ...
-1
votes
1answer
57 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 ...
10
votes
1answer
521 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 ...
1
vote
1answer
127 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 ...
2
votes
0answers
75 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 (...
0
votes
1answer
49 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 ...
4
votes
3answers
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 ...
0
votes
1answer
28 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
106 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 ...
1
vote
1answer
114 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
53 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
27 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
24 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
36 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 ...
2
votes
2answers
74 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
121 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
68 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
66 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 ...
8
votes
4answers
457 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
151 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
111 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
93 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-...
-1
votes
1answer
83 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
1answer
35 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 ...