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

Array of all permutations in C

Is this a good compromise between readability and verbosity? Are there any bugs, additional error checking, or extraneous code as well? ...
2
votes
3answers
43 views
2
votes
1answer
34 views

Filter list items

I have a list of items I pull from SharePoint and want to filter them in my custom list view page. So my function works exactly how I want, but it seems messy and I'm hoping someone could point me to ...
1
vote
0answers
15 views

Segmented (Bit) Sieve of Eratosthenes in Java

I am trying to create an efficient implementation of the segmented sieve of Eratosthenes in Java, similiar to the one in C found here: https://github.com/kimwalisch/primesieve/wiki/Segmented-sieve-of-...
2
votes
2answers
33 views

Counting Valleys - HackerRank Challenge

For this challenge on HackerRank: A valley is a sequence of consecutive steps below sea level, starting with a step down from sea level and ending with a step up to sea level. Given Gary's ...
3
votes
2answers
75 views

Loop through products and return first product that matches criteria

I am writing a function which loops through an array of products. The function needs to return: the ID of the first product that has an image and is ...
8
votes
5answers
2k views

Find The One Element In An Array That is Different From The Others

https://www.codewars.com/kata/find-the-stray-number/train/javascript I solved this challenge by sorting from least to greatest, and checking if the first element in the array matched the second ...
0
votes
0answers
88 views

Minimum sum of elements, taken 2 at a time

Update: I had not recalled the question correctly and ended up with the wrong question. I have now updated the question and the solution: The question is: Given an array of integers say [8,4,6,12,10] ...
1
vote
3answers
83 views

PHP - check if array includes value and return value if true

I developed the function array_includes which checks if an array contains a value and returns it. I would like to know if there is already such a function which is ...
2
votes
1answer
52 views

A heap-allocated texture class for a console renderer

I am working on a console renderer and I want a heap-allocated dynamic texture class. Since I am quite new to C++, I just want to check the memory management, if I destroy all pointers correctly etc. ...
1
vote
1answer
84 views

Union, Intersection and Diff of two sorted arrays in C#

This is the original question https://www.geeksforgeeks.org/union-and-intersection-of-two-sorted-arrays-2/ Given two sorted arrays, find their union and intersection. ...
7
votes
3answers
20k views

Binary search for inserting in array

I have written a method that uses binary search to insert a value into an array. It is working, but i would like to get a second opinion to see if i didn't write too much code for it. aka doing same ...
1
vote
1answer
96 views

Manipulating arrays to extract unique objects and count occurrences

The data describes cycling activities (key1) and chunks of them (key2). In total there are around 1,000 ...
2
votes
2answers
72 views

Find all local maxima in a one-dimensional array

I implemented the following class (it works) and I just want to hear your opinions about best practices and what can be improved. The idea was to do it using mostly arrays. The class just finds the ...
3
votes
1answer
89 views

C++ Arraylist Implementation

I am a new C++ developer who, coming from Java, am having issues in understanding some of C++'s key memory management features. Below is my attempt at an ArrayList implementation and I would really ...
6
votes
2answers
2k views

3Sum implementation

I have recently started to work through the problems on Leetcode, for the sake of bettering my own skills as well as preparing for interviews. I was faced with the 3Sum problem which is: Given an ...
4
votes
1answer
108 views

A basic multi-dimensional array

I have been lurking on the C++ side of stack-overflow only long enough to know there are a lot of beginners and intermediate programmers baffled by multi-dimensional arrays. I've seen a lot of ...
-2
votes
1answer
85 views

Parse header information [closed]

Concrete Context: I parse the header information from curl execution/request and get the array named $headerARR. At this point it looks like the next example, but ...
3
votes
0answers
82 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
2answers
51 views

Maximum contiguous sum in an array

The following code is my solution for the following Daily Coding Challenge Given an array of numbers, find the maximum sum of any contiguous subarray of the array. For example, given the ...
3
votes
1answer
68 views

LeetCode: Best Time to Buy and Sell Stock II

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

Finding if there is sub array with sum equals to 0

I have asked to write a program to find if there is a sub-array with a sum equal to zero using JavaScript. Is this a good solution? How can I improve it? ...
2
votes
0answers
126 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 ...
5
votes
1answer
80 views

EEPROM-based filesystem, aiming for Misra C++ 2008 compliance

I'm writing code for embedded systems (IAR compiler) and it should adhere to Misra C++ 2008. This limits the available features of the language quite a bit: no C++1x features use of the standard ...
2
votes
2answers
53 views

Permutation of words in a sentence

There is a problem which discusses in how many ways can the words in a sentence be permuted . I wrote a code as follows which works for the sentences (I think so) . It would be helpful if anyone can ...
3
votes
0answers
97 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-...
3
votes
2answers
99 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, ...
4
votes
1answer
48 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 ...
2
votes
0answers
32 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 ...
1
vote
1answer
47 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 ...
3
votes
1answer
48 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
103 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 [...
1
vote
1answer
35 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 ...
7
votes
3answers
170 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 ...
11
votes
3answers
884 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
2k 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 ...
4
votes
2answers
1k views

If non-array property exists convert it to one and push new value

Is there a simpler/shorter/better way to do this? ...
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 ...
8
votes
2answers
163 views

Associating degrees with notes of scales

I have a JS file that creates an object with notes from a music scale when given a key (aka tonic/ note). The code works and does what I want it to do. I need a critique on the way it's written, what ...
6
votes
3answers
133 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
50 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
32 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
47 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
41 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 ...
4
votes
1answer
61 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 ...
3
votes
1answer
46 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
460 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 ...
4
votes
3answers
1k views

(Re)Creating a tree from a flat collection (or “unflatten” a tree)

I need to create a tree from a flat collection. The order of elements is defined in a specification so it's rather impossible that it will ever change... but I want the whole algorithm to be ...