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.

0
votes
0answers
8 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
36 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
29 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 ...
0
votes
0answers
21 views

Prints information about a restaurant (provided by user input) using a .txt file [on hold]

My code works, but not the way I want it to. If a user provides a string, even if the string doesn't match a name in the array, it will print information about all 5 restaurants. If I put a break ...
2
votes
2answers
41 views

Remove and Add items from array in nested javascript object

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

What's the complexity of the algorithm to find median of 2 sorted arrays [migrated]

There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be \$O(log(𝑚+𝑛))\$ Here is the code that I ...
5
votes
2answers
67 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
32 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
2answers
89 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. <...
1
vote
1answer
20 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
111 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
795 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
23 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
132 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
86 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
222 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
56 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
47 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
358 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
61 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
70 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
31 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
75 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
146 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 ...
1
vote
0answers
201 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
49 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
76 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 ...
0
votes
0answers
50 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 ...
5
votes
2answers
256 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
39 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
714 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
39 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 ...
1
vote
1answer
114 views

Calculating array size in C++

This code shows two ways to calculate size of array of any type. I would like to know, which should be preferred? Is there any advantage/disadvantage? ...
6
votes
3answers
140 views

C++14 std::array implementation

I invested an hour or so to reimplement the C++ header <array>. Most stuff is in the namespace my_std, but ...
1
vote
0answers
32 views

Filtering users in socket.io and seeing who is online

While implementing socket.io on my server, I ran into some problems and eventually fixed them. The code below is fired on the connection event of socket.io: ...
1
vote
1answer
40 views

Find closest greater and smaller number from a sorted array

I have a sorted array. It can be empty. I have to find its closest greater and smaller number. If the given number is present in the array, it will be considered as greater number. I implemented it ...
0
votes
1answer
45 views

Reduce a grid array [][] into a string

I have a class with a property of grid[][] and each value is either true or false. I need to convert this to a string with letters o and b in place of the boolean. ...
0
votes
1answer
34 views

Two functions that move array elements [closed]

These two functions act on a stack, an array of integers (whose first element is the top of the stack, LIFO). The first function retrieves the first element and puts it at the end. The other is the ...
0
votes
2answers
57 views

Filter non-duplicate objects from collection

I need to filter an array of form controls to check for duplicate values. I have written the following algorithm to identify and return an array of the controls which have are duplicates. I have not ...
1
vote
1answer
94 views

Products excluding each element of the array

Given an array of integers, return a new array such that each element at index i of the new array is the product of all the numbers in the original array except the one at i. For example, if our ...
3
votes
3answers
91 views

Check if a postcode is in a list

I'm looking for improvement / advice / reviews on how I can improve this code. I feel like there is a better way or more efficient way of doing this and I am over looking it. The Plugin I made is ...
1
vote
2answers
98 views

Recursive Transversal (Python)

For a programming challenge I was doing, I needed to traverse a list of lists, and while writing the standard 2D traversal function, I thought why not generalise it, so I did. Here's my best effort: ...
3
votes
2answers
90 views

Efficient method to look for an instance of an object in a collection

I'm trying to determine if an instance of an object exists within a collection. I'm using array_walk_recursive to walk and check the leaves of an array. I've added a small short circuit, but still ...
3
votes
2answers
93 views

Storing computed values in an array [closed]

In several places I need to compute the next value, given a N: double size = 1.0 / Math.Pow(2, N); Since I won't be computing this value for N > 15 I have ...
4
votes
2answers
112 views

Sorting an array of numbers by descending frequency

Somebody asked me to create a code that orders unique numbers of an array according to their frequency, ie: {1,3,3,4,4,4,4,4,2,2,5,5,5,5} to ...
0
votes
4answers
106 views

Counting number of pairs in an integer array

So, I wanted to have the count for number of pairs of same integer there are in an array for which I used a HashMap Input contains two lines: Integer n: Signifies the size of input Input ...
2
votes
1answer
164 views

Rotate matrix 90 degrees

I recently did problem 1.7 Rotate Matrix in Cracking the Coding Interview. I realized my code is very different than what is in the book and what I am also fining online (I'm having trouble following ...
1
vote
1answer
44 views

Monitoring navigation function: logic judgment

Write a simple monitoring navigation function. I feel logic judgment still needs to be optimized. I don't have a clear idea right now about code logic such as reducing ...