Stack Exchange Network

Stack Exchange network consists of 175 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.

2
votes
0answers
29 views

Find sum of neighbors in a 2D array

Write a function that takes 2 inputs: a matrix, for example 2-dimensional array, and indices, for example [row, col] This function should return the sum of all the second input's neighbors (up, ...
3
votes
0answers
28 views

Alternative for VLOOKUP/Index-Match in VBA

I am sharing this function I wrote with the community to provide an alternative to slow VLOOKUP and/or Index-...
4
votes
1answer
37 views

LeetCode: Intersection of two arrays ii C#

https://leetcode.com/problems/intersection-of-two-arrays-ii/ Please review for performance, I am having a problem with using TryGetValue, if someone can explain how this can be used in here. Given ...
3
votes
0answers
35 views

LeetCode: Best Time to Buy and Sell Stock II C#

https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/ Please review for performance. Say you have an array for which the ith element is the price of a given stock on day i. ...
2
votes
0answers
25 views

LeetCode: Remove Duplicates from Sorted Array

Please review for performance https://leetcode.com/explore/featured/card/top-interview-questions-easy/92/array/727/ Given a sorted array nums, remove the duplicates in-place such that each ...
3
votes
1answer
45 views

LeetCode: Transpose Matrix C#

Please review performance https://leetcode.com/problems/transpose-matrix/ Given a matrix A, return the transpose of A. The transpose of a matrix is the matrix flipped over it's main ...
1
vote
0answers
88 views

LeetCode: trapping rain water C#

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. The above elevation map is represented by array [...
0
votes
0answers
40 views

Finding if there is sub array with sum equals to 0

I have asked to write a program to find if there is sub-array with sum equals to zero using javascript. Wrote following code.Is it good solution ? How I can improve it ? ...
11
votes
3answers
873 views

Code downloads a text file from a website, saves it to local disk, and then loads it into a list for further processing

My program opens a website and downloads a text file. The text file is a simple file with one word per line. I save the file to local disk and then create a list to hold each line of the text file ...
11
votes
5answers
1k views

Check if three arrays contains the same element

Do 3 arrays contain a common element, if they contain output it. For example: [1,2,3], [2,3], [2,4] -> answer = 2 ...
3
votes
0answers
68 views

A fixed-size dynamic array

Background I implemented the historic std::dynarray according to the specification under the name dynamic_array in C++17. ...
1
vote
1answer
49 views

Zig-zag array - solution

The problem For any given array, find a corresponding zig-zag array such the each element (a,b,c,d,e...) follows the rule: ...
4
votes
1answer
24 views

Finding the number of pairs in an integer Array

This function returns the number of pairs of the same elements in the array It takes, array length and the array as the parameter n: Length of array ar: Array of integers for example ...
2
votes
0answers
46 views

Python list operation - merge adjacent cubes into minimum number of shapes

I am hoping to find a way to make the process a lot faster. The lists are made of rows of 6 numbers, i.e. [[float] * 6, ...]. The intent is to pass a list of cube ...
-2
votes
1answer
40 views

Compute the results of a race against Achilles [closed]

I was given the task to write a code that takes inputs from the user that include the following: length of a certain race the speed of Achilles (the main participant) the number of participants ...
3
votes
1answer
45 views

Partial Sudoku Verifier

To practice my JavaScript for future employment, I've decided to take up the challenge of writing a javascript sudoku verifier. This code only verify's one of the ...
5
votes
2answers
457 views

Array Stutter Implementation

I was assigned this homework assignment to complete. The question originates from CodeStepByStep. Below is the prompt for the question: Write a function stutter that takes an array of Strings as a ...
3
votes
1answer
59 views

Count the number of words and lines that have multiple vowels

I am working on this coding problem: Count the number of words & lines that have more than X vowels for every Y words in every Z line. Basically the input string has multiple lines and I need ...
1
vote
1answer
33 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
31 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
40 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
75 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
90 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
96 views

A static array implementation in C++

I'm implementing a basic array data structure with basic functionalities. ...
1
vote
0answers
52 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
106 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
761 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
759 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
69 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
110 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
47 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
150 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
62 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
24 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
85 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
45 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
49 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
33 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
41 views

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

I have the following object at React state: ...
2
votes
3answers
101 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
92 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 ...
1
vote
0answers
103 views

Angular 7 - 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
127 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. <...
2
votes
1answer
65 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
128 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
806 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
24 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
142 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
108 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 ...