Stack Exchange Network

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

1
vote
1answer
66 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
93 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
23 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
31 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
43 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
33 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
37 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
80 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 ...
2
votes
3answers
74 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
54 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: ...
2
votes
2answers
80 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
87 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
107 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
1answer
54 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
72 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
43 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 ...
4
votes
1answer
141 views

Sorting an array in C++

This started as a simple exercise in sorting an array. I wanted to make it a bit more complex which is why I made it a 2D array. I then noticed that each pass that checked and swapped values, it was ...
1
vote
2answers
76 views

Shuffle array elements by rearranging the key value associations

PHP's shuffle() function destroys the array keys, so I decided to write a shuffle function that doesn't do that and instead rearranges key-value associations. As I ...
2
votes
2answers
38 views

Compare an array with a file and form groups from elements of an array

I have a text file with letters (tab delimited), and a numpy array (obj) with a few letters (single row). The text file has rows with different numbers of columns. ...
1
vote
1answer
33 views

Create an Array of Objects for Patch Notes in React

I was looking to get some reviews of my code, so I can improve my writing. Functionally it works the exact way I want it to based on my patch notes .md file. I'm open to all suggestions for improving ...
11
votes
2answers
161 views

C++ data type to store and manipulate individual bits

The use cases I’m facing require me to have a C++ data type that can store and manipulate the state of somewhere between 400 and 500 bits. In addition it is necessary to be able to store that state ...
4
votes
2answers
35 views

Replace array element with multiplication of neighbors in Scala

Given an array of integers, update the index with multiplication of previous and next integers, Input: 2 , 3, 4, 5, 6 Output: 2*3, 2*4, 3*5, 4*6, 5*6 Following ...
1
vote
2answers
79 views

Write byte array to end of file

I'm writing a byte array at the end of file. The code works fine, but can you please suggest performance improvements? ...
1
vote
1answer
50 views

A 'slow sort': repeatedly swap the first misordered pair

A 'slow sort' is probably the slowest practical sort. It compares each element with the elements after it, and swaps immediately if one is greater than the other, and goes back to the start of the ...
0
votes
2answers
38 views

Wrapping certain elements in an array with an array with PHP

I have a function that's doing this correctly, but I feel as though this can be done (possibly) with minimal code, with recursion, but I'm just wracking my brain. Basically I have JSON that gets ...
2
votes
3answers
45 views

Select data from csv and make associative array

I've got a .csv file with ZIP codes containing the city and its sub-districts 67401,City 1,district_a 67401,City 2,district_b 67401,City 3,district_c 67401,City 3,district_d 67401,City 3,district_e ...
4
votes
2answers
44 views

MaxHeap implementation in JavaScript

Here is MaxHeap implementation in pure JavaScript: ...
2
votes
0answers
59 views

Project Euler #81 in Haskell: minimal path sum through a matrix

I just completed Project Euler Problem 81 in Haskell: In the 5 by 5 matrix below, ...
2
votes
2answers
43 views

I/O-TxtFile Line Distance Program

I am trying to write a lab/program that loops through a .txt input file. Reads an entire line of data as a string, then splits that string into an array delimited by a space. If there are 4 items in ...
1
vote
2answers
68 views

Printing elements of an array in C

I'm trying to print the elements of an array in a fashion that resembles thism where SIZE is a constant: ...
3
votes
1answer
75 views

List of word to list of index in a vocabulary [closed]

I have a dataset composed of ~700k samples. Each sample is composed of n_features features. Each feature is a word. Each feature has his own vocabulary. The size of the vocabularies range from 18 to ...
1
vote
1answer
48 views

Longest Substring Without Repeating Characters in Scala

Question is taken from Leetcode and solution works for their test cases. I do see a scope of improvement and make it more functional (getting rid of vars and mutables data structures). Please suggest ...
4
votes
1answer
92 views

Finding decreasing sequences in an array of numbers

Ants Requirement Given a natural number \$n\$, representing the number of days the study is made, and then a number \$x\$ of \$n\$ natural numbers, representing the number of working ant ...
1
vote
1answer
40 views

Get the most frequent number and least frequent duplicate in array

This code gets the most frequent number and least duplicate number in an array. How can I optimize it and improve its performance? ...
3
votes
1answer
81 views

Checking whether given array is sorted by divide-and-conquer

I've written a code that I try to use divide and conquer approach to determine if the given array is sorted. I wonder whether I apply the approach accurately. ...
-2
votes
1answer
49 views

Append to array if not empty [closed]

I want to call a series of functions to build up an array, like so: ...
-4
votes
1answer
84 views

Bidirectional bubble sort using goto [closed]

I am aware of Dijkstra's paper on why goto is harmful, but I thought it would still be fun to make a bidirectional bubble sort using ...
1
vote
2answers
107 views

A scalable way to remove duplicates from Arrays without extensions in Swift 4

This method is an attempt at removing duplicates from arrays with scalability in mind in Swift 4 without the use of extensions. I am asking for any suggestions, criticisms, and/or observations. ...
1
vote
1answer
62 views

Recursive trim() function to handle arrays and objects

I have come up with a recursive function which applies trim() recursively to all string members of an array/object. I don't have any specific quandaries about my ...
1
vote
1answer
52 views

Check if list contains a pair which adds up to a given sum

Kindly review this scala code for given problem and suggest improvements. Problem - Given an array of integers and a target sum, check if array contains a pair which adds up to sum. Example - <...
8
votes
2answers
241 views

std::array implementation

I'm creating my own implementation of the STL, compliant with the C++17 standard. The only purposeful differences are that the namespace is hsl (homebrew standard ...
0
votes
1answer
61 views

Checking if an array element exists in a JS object

I have a feature in my application that should allow users to select items in a drop down menu and move them up and down. Once they select and click on the button I have to loop over the array of ...
1
vote
1answer
48 views

Add Strings in-between index of ArrayList if not already exists

So as the title states, I am trying to add a specific Items to an ArrayList if they not already exist. So here is how the Array starts. [a, b, c, d, e, f] I have ...
5
votes
3answers
440 views

Count sub-sequences of an array having median lying in that subsequence itself

We need to calculate the number of sub-sequences of an array having its median lying in the sub-sequence itself. My code is - ...
2
votes
1answer
60 views

Printing a K-ary tree stored in level-order in an array

I am given an array that represents a k-ary tree (I am also given the branching factor "k") that is stored in level order. My task was to print the tree in level order. For example a trinary tree ...
0
votes
2answers
71 views

Convert HTML input string to JavaScript Array literal

I am trying to accept JavaScript array literals in an HTML text input. The problem is that HTML text inputs are captured as strings, such that an input of ...
3
votes
1answer
95 views

Effective 3d array transposition with R/C++ (Rcpp)

Task is reshape 3d array from [row, col, slice] to [slice,row,col]. I tried implement base::aperm analog with Rcpp. ...
1
vote
1answer
23 views

Combine contiguous spreadsheet cell references into larger ranges

For a hobby project, I am using openpyxl to export Excel workbooks as JSON. Part of this involves identifying the formatting applied to cells, and serializing this information (provided the format is ...
0
votes
1answer
44 views

Find the combination of matches which are closest to each other

Problem - Given three sorted arrays find combinations which are closest to each other. example - ...
1
vote
1answer
35 views

Best way to split array to two sub-arrays, with maximum absolute difference between them

Given array a, we want to find an index k in range [0, a.length-1] such that: ...