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
1 answer
23 views

A (Sort of) Generic Stack Implementation in C using Macros

I spent some time implementing a generic stack in C using macros. Apart from general bugs and bad practices in my code, I was wondering about the viability of an implementation like this that uses ...
user avatar
0 votes
2 answers
40 views

Shortest way possible to generate javascript string from a large array of values to A, B, C and n others

I have an array of values containing names, e.g. let members = [{id: 1, name: 'Tyler'}, {id: 2, name: 'John'}, {id: 3, name: 'Dayo'}, ..., {id: 7, name: 'George'] ...
user avatar
1 vote
0 answers
40 views

Minimum number of swaps to sort a array, but swaps only allowed with elements 2 apart

I wanted to solve a problem where I sort an array of any size and return the minimum number of swaps. The explanation for the distance 2 is that I choose 3 neighboring elements ABC and then swap them ...
user avatar
2 votes
1 answer
40 views

make html table in sync with javascript array

I have an array of users containing user name with their rules on my practice project I have generated a table in HTML from that array in JS, So I can change the ...
user avatar
0 votes
1 answer
42 views

Java - Select the maximum integers from sliding windows over an array

So I have the following algorithm. Given an array A[0 ... n - 1] and the window length w, compute all the windows ...
user avatar
  • 25.6k
1 vote
1 answer
57 views

Type safe generic array in c

Here is my type safe dynamic array. I'm eventually going to make a hash table in C. I'm just wondering if anything seems wrong or out of place. Thanks. ...
user avatar
0 votes
1 answer
50 views

PHP assign values within in_array

What is a more efficient way of writing this sample code? Its purpose is to create a variable for days of the week based on a numerical value. This data is obtained from user input checkboxes. If the ...
user avatar
  • 113
2 votes
1 answer
55 views

String / Char Vector Concatenation Performance Comparison in Matlab

Considering the suggestion of using modern string arrays instead of char vectors proposed by Cris Luengo, I am trying to make a code snippet for performance comparison of these two cases. The ...
user avatar
  • 3,546
2 votes
1 answer
66 views

Function that sorts nestedArray[][]'s

I'm fairly new to coding and am trying to learn more about best practices. I wanted to have an nestedArray of objectArrays, and I wanted to be able to sort the elements in each objectArray based on ...
user avatar
  • 21
1 vote
2 answers
63 views

Simple snake game with C and raylib

Made a simple snake game using C and raylib for graphics, Would like to be critiqued on the clearity and efficiency of the code. ...
user avatar
4 votes
1 answer
396 views

Writing a Java program that outputs a calorie/macronutrient plan for getting in shape over a certain amount of weeks

I am new to programming and was working on a project that calculates an entire "diet plan" as well as a projected weight goal for each week. There are three objects that all have methods ...
user avatar
3 votes
1 answer
60 views

Langton's Ant cellular automaton in Java

I made a couple of little games and cellular automata in Java. For every new 'game', I used the same code as a base, except for the game logic of course. With every iteration of me customizing my ...
user avatar
0 votes
1 answer
73 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
34 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
377 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
  • 163
2 votes
1 answer
87 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
128 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
83 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
248 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
75 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
92 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
94 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
24 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
  • 319
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
55 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
101 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
109 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
285 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
104 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
127 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
62 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
100 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
55 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
105 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
112 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
79 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
956 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
99 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
147 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
47 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
  • 319
0 votes
0 answers
63 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
37 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
93 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
856 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
84 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

1
2 3 4 5
42