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
2
votes
2answers
54 views

Python program to get all non unique elements in an array

Given an array of ints as input: non_unique([1, 2, 3, 1, 3]) returns [1, 3, 1, 3] non_unique([1, 2, 3, 4, 5]) returns [] non_unique([5, 5, 5, 5, 5]) returns [5,5,5,5,5] non_unique([10, 9, 10, 10, 9, ...
-3
votes
1answer
36 views

Remove duplicated code from a Python function that gets data from and endpoint and, after manipulating it, returns the manipulated version [closed]

I have written the following function for a CLI tool, it works as expected but it also contains duplicated code. ...
3
votes
2answers
42 views

Improving performance of moving arrays into an array

I am loading a bunch of arrays and putting them into a single array. The loading of the data is negligible, but putting it into combinedArray takes significant ...
3
votes
2answers
88 views

3D metrics for segmentation evaluation

I am new to programming and I am trying to develop a machine learning approach for image segmentation (https://en.wikipedia.org/wiki/Image_segmentation) and here I want to evaluate the predicted (...
3
votes
1answer
95 views

Random String Chooser

I was tasked with creating the class RandomStringChooser that prints the strings in the passed array in a random order, based on the ...
5
votes
2answers
107 views

A static array implementation in C++

I'm implementing a basic array data structure with basic functionalities. ...
1
vote
0answers
53 views

Check for key in two arrays in order to control flow of the program

I have a container. This container has exactly this structure: ...
3
votes
1answer
114 views

Swift function to find a specific set of combinations of 3 digits within a larger integer array

I asked this question on Stack Overflow and was directed here. I'm working on a function that will help me quickly find all the upper structure triads (3-note chord) that I can add to a 4-note 7th ...
5
votes
2answers
802 views

Find hamming distance between two Strings of equal length in Java

I have a private class that I want to be able to find the shortest Hamming Distance between two Strings of equal length in Java. The private class holds a char[] ...
11
votes
4answers
768 views

Cropping a message using array splits

I am trying to write a simple function to crop a given message to a specific length but at the same time not to cut the words in between and no trailing spaces in the end. Example: Input String: ...
1
vote
1answer
71 views

Go command-line tool to do some simple byte manipulation

I have some files containing 16-bit words in big-endian order, and a tool to process them that assumes little-endian order. I therefore need to swap the order of each pair of bytes in my files. This ...
4
votes
1answer
137 views

Program to output the same highest numbers in an array

Here is my program to find the largest number(s) in a list of elements, possibly non-unique (in Python): ...
2
votes
0answers
50 views

Breadth-first search in Java: Competitive style - follow-up

I have improved my BFS in Java according to vnp's suggestions. Again, we wish to find shortest paths in directed unweighted graphs using BFS, competitive style (no ...
3
votes
2answers
154 views

Finding products of all other members of an array

I had the following interview question: Given an array of integers, for each member of the array find the product of all the other members of the array. So for instance, if you have this array: <...
3
votes
2answers
79 views

Leetcode - First Unique Character in a String

Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. Examples: ...
1
vote
1answer
33 views

Leetcode - product of array except self

Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. Example: ...
2
votes
0answers
16 views

RC4 in Sinclair BASIC; Working around one-indexed arrays

This is a program written in Sinclair BASIC (48 BASIC) for the Sinclair ZX Spectrum. It uses a hardcoded key (null right now) as seen in the bottom and outputs a stream of integers generated with RC4. ...
1
vote
1answer
225 views

Convert nested array of values to a tree structure

I have a nested array that represents a parent child relationship, that I need to convert to a tree structure. Example nested array ...
1
vote
2answers
46 views

Combining arbitrary number of lists inside json

I have some JSON where each key stores an array, and I need to combine all those arrays into a single array. My current solution doesn't seem the most friendly to review, but without ...
2
votes
0answers
55 views

Efficient counting sort for large byte arrays in Java

I have this counting sort for byte values running in linear time with respect to array length: Arrays.java ...
4
votes
1answer
36 views

Super fancy list constructing in Python

Out of curiosity I was discovering the potential of the Ellipsis object in Python (...), and I discovered it doesn't do a whole ...
2
votes
2answers
44 views

Remove and Add items from array in nested javascript object [closed]

I have the following object at React state: ...
2
votes
3answers
121 views

Statistical methods using PHP (mean, co/variance, standard deviation, skew, correlation)

Functionality This class has a list of statistical functions such as mean, variance, standard deviation, skewness, and it works okay. These functions are applied to arrays of charts data. It is an ...
5
votes
2answers
135 views

Hash table with dynamic sized array in C

To gain a broader insight in things many (high-level language) programmers nowadays take for granted, I decided to study some of the more basic ways of storing data in memory. I wrote a program which ...
2
votes
0answers
249 views

Mapping nested arrays from API response

I have some selects on my html page that I want to populate with the response from my backend API. The response looks like this JSON response ...
6
votes
3answers
137 views

Rotate array to the left

I am a beginner in programming. To rotate the array to left, I have written the below code. Please point out how to optimize the code and anything I am doing which is not good programming practice. <...
3
votes
1answer
100 views

Groovy script to get average price per group from different data arrays

I've been trying to learn Groovy lately and I tried to solve a problem which involves designing a routine that will calculate the average Product price per Group. I have the following data: ...
3
votes
2answers
131 views

Efficient way of flat mapping a range of a multidimensional random access collection

I've recently answered a question about reading elements from an array of arrays. A way it could be interpreted is that the OP wanted to read a range that could span over multiple subarrays of the 2D ...
11
votes
5answers
819 views

Easy to read palindrome checker

I made a palindrome checker that's supposed to be designed to be simple and easy to read. Please let me know what you think. I believe the time complexity is \$\mathcal{O}(n)\$ but I'm not too sure ...
1
vote
1answer
26 views

Dynamically-resizable array implementation, for use in a game-dev-related library

I've been working on a library that includes a list-like structure, which I use internally multiple times to store different types of structs. However, I'm not entirely confident with my ability to ...
0
votes
3answers
150 views

Finding nth lowest value without any Math max or min methods

So I decided to make a more efficient solution to a Google interview question where they ask you to either find the lowest or second lowest value in an array without using the max or min methods. I ...
2
votes
0answers
144 views

VBA array functions: push, pop, shift, unshift

I want to write my snake game procedurally, using as much windows call as I can so as to practice. Looking into GetAsyncKeyState to capture keyboard inputs and play sound functions. Also making a ...
1
vote
1answer
228 views

Equity data processing: Fast and/or efficient file writing using PHP

Problem This project gets the past ~20 days of an equity data (such as $AAPL, $AMZN, $GOOG) plus the current equity "quote" (which comes every 60 seconds using a free API) and estimates seven "real-...
3
votes
1answer
61 views

Array that stores values from two ranges and compares if one cell is blank

This is my first Array in VBA for Excel, but I need some help to optimize the code and try to reduce the number of If statements. The long and short of the code is ...
3
votes
1answer
57 views

Counting hits by domain

I wrote this algorithm which takes input data from something like a CSV file or a large array that contain a series of String elements in the format of "count, FQDN" and then adds or increments the ...
4
votes
1answer
500 views

Find if one list is a subsequence of another

So the problem of verifying if a list is a subsequence of another came up in a discussion, and I wrote code that seems to work (I haven't rigorously tested it). IsSubequence.py ...
2
votes
2answers
72 views

A Java Iterable over multiple arrays

GlueArrays is used for iterating over an array of arrays, and it looks like this: Main.java ...
1
vote
2answers
93 views

JavaScript Spiral Matrix Coding Challenge

A whiteboarding challenge: Given a 2D array (matrix) inputMatrix of integers, create a function spiralCopy that copies ...
2
votes
0answers
35 views

Fixed Size Resource Array with Versioned Indexes

I'm trying to implement a fixed sized array that uses versioned keys for dangling safety. This structure is similar to a slot map data structure, with the exception that this does not automatically ...
2
votes
2answers
79 views

TicTacToe game in C++ made with 2D arrays

We have been learning C++ the previous semester and I made this simple TicTacToe game at the end of it. We haven't yet covered topics of vectors, classes, objects, exception handling etc. so with this ...
5
votes
1answer
261 views

(Codewars) Range Extraction

Kata: https://www.codewars.com/kata/range-extraction/python A format for expressing an ordered list of integers is to use a comma separated list of either individual integers or a range ...
2
votes
0answers
805 views

Deepest pit of an array

Following is based on a problem description from a Codility test, as a task in an interview. DeepestPit - problem description A non-empty zero-indexed array B ...
2
votes
2answers
64 views

Split an array of items into several arrays, given a condition

The question is very simple : I have an array of items, that all have a date. According to the date, I would like to split this array into several arrays. In my case, I would like to split the array ...
4
votes
1answer
80 views

Code to replace list of integers with nearest bigger element

The original question was in the context of an array, but I just used a list without changing the length for easier debugging purposes of toString(). Given an ...
1
vote
0answers
54 views

Simple dynamic array template

For my game engine I needed a simple templated array class that can be safely passed across module boundaries. It's not supposed to be a replacement for std::vector and thus doesn't need all of its ...
0
votes
2answers
33 views
5
votes
2answers
462 views

User input happy birthday program

For self-study homework I made a Java program that takes user input, creates people as objects, and says "Happy Birthday" to each person. I am just wondering what mistakes I made here or how it could ...
2
votes
2answers
42 views

Iterating through two objects with different structures in parallel

I have two objects, one input = Array<Type> and one stored = Array<{..., Type}> What's the best (cleanest) way to ...
5
votes
5answers
757 views

Checking if an integer permutation is cyclic in Java

A an integer permutation array[] is said to be cyclic if and only if we can choose an arbitrary element at position i, move it ...
1
vote
2answers
41 views

Selecting lowest position from 'array'

My goal is to move a 'monster' (mX, mY) in a 2d grid towards the player (pX, pY). The monster can move 8 directions. I have ...