2022 Developer Survey is open! Take survey.

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
0 votes
0 answers
14 views

Can I optimize my implementation of generating Fibonacci series using recursion?

My function accepts a number, which generates total Fibonacci numbers. I am using recursion. Please follow the code below, ...
user avatar
0 votes
1 answer
28 views

Integer array to string

This function creates takes an int * buffer and creates a neatly formatted string (useful for printing the contents of an array). Is the code easy to follow? Is it ...
user avatar
  • 155
6 votes
2 answers
350 views

std::array based push-only circular buffer

Minimal implementation of a circular buffer based on std::array, where elements can only be pushed and iterated. I'm interested on potential failures and very trivial optimizations, as I'd like to ...
user avatar
  • 161
2 votes
1 answer
79 views

Returning all divisors of a number as a matrix with N X 2 dimensions

I have developed a class structure with methods to return a matrix from a single input array. The objective is to insert the middle value of the array so 2n remains ...
user avatar
2 votes
1 answer
121 views

Sum two vectors in x86 assembly

I recently made a program with C++ and ASM. Can anyone help me make this code a more efficient one, in the ASM part or both. I would really appreciate it because I don't know every ASM instruction and ...
user avatar
0 votes
3 answers
61 views

Sum up nested array of objects based on keys

I have this function that should take some array of objects and sum up the values of the inner objects based on some keys, and conditionally add to it some values from another object. Is there a way ...
user avatar
  • 189
4 votes
2 answers
244 views

Porting PHP's array_push to Python

I am new to Python but not new to PHP. I've started porting PHP APIs to Python hoping to learn the Python language along the way, currently trying to grasp List, Dict, Set, Tuple. I tried writing PHP'...
user avatar
3 votes
1 answer
74 views

Practicing with array

The class "post" only has simple methods like getters for the ID(long) and number of likes(long). Is how I wrote my method below accomplishing anything? Is it doing what I want it to do? I ...
user avatar
  • 33
0 votes
2 answers
89 views

VBA - Compare & Consolidate Dynamic Arrays

Background The CSV files being used can be 6+ mill records in size, using a small sample size to proof the methodology. Why are you doing this on excel? Access or SQL would be quicker My company has ...
user avatar
  • 11
5 votes
1 answer
91 views

Why is this tensor contraction so slow and how can I make it faster?

I am trying to calculate a specific complicated tensor contraction (of complex valued tensors) which appears as part of some other calculation and is called multiple times in a row, about 100 times or ...
user avatar
0 votes
0 answers
22 views

How to optimize Uint8Array#replace in JavaScript?

I am considering implementing a string type in JavaScript, in a programming language that compiles to JS/Swift/Kotlin/Rust. So I have here implemented a prototype of how the ...
user avatar
  • 299
2 votes
1 answer
69 views

Java - Breaking a large 1-D array into a 2-D array

Java's largest array length is 2^31 – 8 = 2,147,483,639, which is an int consisting of 32-bits. In the case where we want to store more elements, we are better off ...
user avatar
0 votes
1 answer
47 views

Distribute items over array in order to minimize the difference between min and max array values

I came across this problem in a programming challenge a few days ago. I came up with the implementation below, however it resulted in a "time limit exceeded" failure for a few of the test ...
user avatar
2 votes
1 answer
83 views

Replace nested for loops when assigning intial conditions in a 4-dimensional array

I create a 4-dimensional (x, y, z, t) array of zero values. I then set the initial values at t = Tmax. To do this, I use a nested for loop. I attempted to improve ...
user avatar
  • 69
1 vote
1 answer
86 views

Suggestions for improvement for generic array and map functions in Go 1.18

Yesterday I build some generic functions for the new official Golang 1.18 release. What do you think about it and what could be added and improved? ...
user avatar
7 votes
1 answer
281 views

Pseudo-Generic Array Stack in C

I have implemented an array based pseudo-generic stack in C using macros. The code works fine for all data types. Is it a good idea to implement such a data structure using macros? array_stack.h ...
user avatar
0 votes
0 answers
27 views

function for adding two 2D matrices of large size obtained by several iterations

I have defined the following function. ...
user avatar
  • 101
0 votes
0 answers
54 views

Looping Through Arrays to Test a Postman Collection

I am relatively new to Javascript and I'm looking to improve the overall flow of the below code. For some reason, I feel as though it can be improved but I'm not really sure how, or where. To me it ...
user avatar
  • 101
3 votes
1 answer
126 views

Randomly set styles with JavaScript

I have created a function which randomly sets styles using CSS selectors. Right now it returns a random item from an array. The program also works with shorthand properties (such as ...
user avatar
3 votes
2 answers
57 views

Find all indices where value of array changes

I try to solve the following problem using Python: Given a 1-dimensional numeric array arr, find all indices where the value of ...
user avatar
3 votes
0 answers
99 views

Two-dimensional arrays in C

I have a bit of trouble with two-dimensional arrays in C. I want to pass such an array to a function accepting a pointer to pointers. I figured no way of really passing the array itself. Furthermore, ...
user avatar
  • 31
2 votes
1 answer
53 views

How many times element of one array occurs in another array?( HackerRank sparse arrays problem)

with basic knowledge of multiset and vectors in c++ I solved the following problem. How can I improve my code and also handle any input errors? Problem statement: There is a collection of input ...
user avatar
  • 89
3 votes
1 answer
96 views

Array rotation in C++

I am completely new to data structures and algorithms. I tried this problem on hackerank. I got the desired output but my code wasn't efficient enough to execute in the given time limit. How can I ...
user avatar
  • 89
-1 votes
1 answer
100 views

Best way to convert the string with Byte sequence to Byte Array

We had a string with byte array (hexadecimal) sequence, like: ...
user avatar
  • 202
-1 votes
3 answers
76 views

Populate array using elements from four source arrays

Long piece of code, I hope it is readable. The code is basically if statements looking at 4 arrays: ArrPnLDataD1, ...
user avatar
1 vote
1 answer
705 views

Student average coding challenge

How can I further optimize following student average coding challenge? Statement:- Given a list of N students, every student is marked for M subjects. Each student is denoted by an index value. Their ...
user avatar
0 votes
0 answers
34 views

Differentiating all the numbers in an array with color codes

Here is a working code for differentiating all the numbers with color codes on an HTML page. How could this code be optimized by using built-In techniques or making use of ECMA Scripts? So that the ...
user avatar
1 vote
0 answers
76 views

How to make recursive a nested map function that takes info from different arrays JS

I am making an inventory application and I must create a function that allows me to perform different operations with the arrays that I have created, the application consumes data from an api and ...
user avatar
3 votes
2 answers
146 views

Modify a WordPress loop to show posts of certain categories, based on user roles

I've got some code that works as intended, but I have a feeling that it's messy. This code is modifying a wordpress loop and the goal is to check the roles of the current user and show posts of ...
user avatar
  • 33
0 votes
1 answer
65 views

Python - Efficiently pick random data from an array, generate random UUIDs and save it all in an Excel table

I wrote the following prototype: ...
user avatar
  • 195
0 votes
0 answers
46 views

How to optimize `push` and `pop` in this tree list algorithm?

So based on this question and answer, which is based on this answer, I have abstracted it out into a reusable module. Basically it is the TLList class, with a ...
user avatar
  • 299
0 votes
0 answers
61 views

Proper way of shifting Array.slice where indexes are not out of bounds

Been wondering for this quite some time now. I'm looking for a cleaner/better way to "shift" a selection of an array. It has to respect the index boundaries, so it can't go negative start ...
user avatar
1 vote
1 answer
44 views

Another generic dynamic arrays in C

Wrote this (and others not here) as an exercise to explore how generics could be implemented in C. Question -- if I were to support out-of-band error setting, how would that look like for ...
user avatar
1 vote
1 answer
109 views

Minimum re-labeling to make an array as close as possible to another one

I have an array with integer labels in [0, n-1], say arr1=[1, 0, 3, 2] with n = 3. And then I have another array again with integer labels in [0, n-1], say arr2=[0, 0, 2, 3]. How can I find the ...
user avatar
  • 13
3 votes
1 answer
36 views

Radio Number station code generator in python (or substitute characters with alternating words)

I'm rather fascinated by radio 'number stations', and in preparing for a D&D game, I wanted to use such a method to encrypt complex messages as seemingly random strings of words. I wanted to add ...
user avatar
1 vote
1 answer
80 views

Proper way to transform nested lists to nested maps [closed]

I want to transform a list of lists of lists that I have in a MongoDB document into a map of maps of maps in my java Domain class. The problem I have is that the fields are mixed between the levels. ...
user avatar
  • 121
1 vote
4 answers
852 views

Find the third biggest integer of an array

How can i make this work with fewer lines? The goal here is to get the third biggest integer of an array. I would also appreciate if someone polished this code. ...
user avatar
0 votes
1 answer
70 views

How to optimize of "Find the largest subarray formed by consecutive integers"

recently solving a data structure question and counter below question Given an integer array, find the largest subarray formed by consecutive integers. The subarray should contain all distinct values....
user avatar
  • 141
2 votes
1 answer
49 views

Change values in array until no consecutive values

I have to find an algorithm to solve this question : You have an array with n integers in it. Make an algorithm that changes array so that there are no consecutive expressions in it and returns the ...
user avatar
  • 23
0 votes
0 answers
126 views

Is there a faster way to read bytes with a FileStream?

So I'm trying to read data and store it in an array as fast as possible and the fastest method I found of doing so was this. ...
user avatar
  • 119
7 votes
3 answers
1k views

Finding the majority element in an array

A list is said to have a “majority element” if more than half of its entries are identical. In this classical problem the goal consists of determining whether a list a of length n has a majority ...
user avatar
  • 393
2 votes
0 answers
39 views

Non-allocating k-nearest-neighbours between two matrices in Julia

I played around with some optimizations when answering this SO question. Sought is a function which given matrices x of size (m, l) and ...
user avatar
1 vote
1 answer
25 views

implode on two level dimensions array

I have an array like this ...
user avatar
-1 votes
1 answer
41 views

Unexpected result when simply filling an array [closed]

So, I have been trying to understand this simple code and why it doesn't produce the expected result. Here is the code : ...
user avatar
0 votes
0 answers
16 views

make an array of cells from formula like in excel with javascript?

I'm working on stylesheet in Excel, and I've made this function of makeCells is there a better way of doing it. I've tried regex to get two cells ...
user avatar
0 votes
1 answer
93 views

Angular and Typescript page with for loop and array

I have a page that shows the result of a quiz and depends on the number of right answer, the user get some rewards. So, if the user get just one right answer, he will get one reward, the others will ...
user avatar
  • 173
2 votes
1 answer
48 views

Exponentiate common factors with JavaScript

I've created a function that exponentiates common factors. I'd like to optimize/simplify it because, as you can see, it's very messy and not very performant ...
user avatar
3 votes
1 answer
47 views

a php function to check a 'deep' array value

I've just coded a little function to check and get a deep array value. Basically, I need to return the value or null if it's not set or does not exists, or in general not useful for databases records. ...
user avatar
2 votes
0 answers
150 views

2d Grid - Iterating by Rows / Cells - Take #3

Edited with a bit more unit tests. Preface Following my second version: 2d Grid - Iterating by Rows / Cells - Take #2 I believe that I am now satisfied with this new version below. There is still one ...
user avatar
1 vote
1 answer
152 views

Optimize Leetcode 239. Sliding Window Maximum using Swift

LeetCode problem 239. Sliding Window Maximum You are given an array of integers nums, there is a sliding window of size k which ...
user avatar

1
2 3 4 5
42