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
6
votes
1answer
123 views

Excel's Dynamic Array Functions…In VBA (No Win 32)

In recent months I have been trying to figure out how in the world one can mimic the functionality of Excel's New Dynamic Arrays exclusively in ...
6
votes
2answers
925 views

Count the frequency of items in an array

The question is: Write a program that prompts the user to input ten values between 80 and 85 and stores them in an array. Your program must be able to count the frequency of each value appears in ...
4
votes
2answers
483 views

Partitioning and sorting even and odd numbers within an array

I solved a problem where it was told to sort an array of numbers such that the even numbers are kept first and the odd numbers should follow. Moreover, the even numbers must be sorted in ascending ...
3
votes
1answer
79 views

Summing same index values in 2D arrays in javascript

After solving a problem, I came to this conclusion. ...
3
votes
2answers
44 views

JavaScript number obfuscater

I got inspired to do this after seeing this repo containing a bunch of weird syntactical quirks in JS, namely this example called "It's a fail!". The example was essentially the following: You ...
8
votes
1answer
126 views

An array with \$O(\log\ n)\$ time complexity for all operations

Does this exist already? It's an array (=variable-size list with integer indices) where add/remove/set and get all take \$O(\log\ n)\$ time. I couldn't find this anywhere, so I made up the name "Log-...
3
votes
2answers
66 views

Minimum Number of swaps required to group all ones together in array of 0s and 1s

Problem Statement: Given a binary array data, return the minimum number of swaps required to group all 1’s present in the array together in any place in the array. ...
1
vote
1answer
52 views

Adding a number to an array of digits

I'm a student in my first semester and in my free time and holidays, I do some java training to keep my mind from rusting...so I downloaded this amazing Digital Algorithms practice app and came across ...
-1
votes
2answers
120 views

Union of two double arrays

I would like to merge two double arrays and remove from the result array approximately equal items. My two input arrays have ...
3
votes
2answers
47 views

Dynamic Array implementation in Python

I am trying to learn data structures by taking this Udemy Course, Easy to Advanced Data Structures by William Fiset. The course provided an implementation of Dynamic Array in Java. To ensure I fully ...
6
votes
4answers
2k views

Create two random teams from a list of players

The task is to create two random teams from a list of players. Given an example of players = ["John", "Mike", "Alice", "Bob"] One example random team would be: <...
4
votes
2answers
44 views

Extract lines under the specified heading

I wrote the following working code, which I just can't stomach: ...
-2
votes
1answer
58 views

Challenge - Construct binary tree from array [closed]

A coding challenge to construct a binary tree from an array. ...
3
votes
2answers
86 views

Algorithm in getting total garnered hours for student using php

Hello I'm calculating now the total garnered hours student get in school using php. (Same concept in getting the total work hours in employee for timesheets) So I have an array $attendance where the ...
2
votes
1answer
72 views

Fast “index of minimum” for distances to points on single thread

The problem in simple words: I have three arrays of double values (x-, y- and z-coordinates) and need to find the index of the point which has minimum distance to a reference points. I do not need the ...
3
votes
2answers
99 views

Finding unpaired number in an odd Array of integers

A non-empty array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be paired with another element that has the same value, except ...
7
votes
5answers
1k views

Finding all possible pairs of square numbers in an array

I am writing a program that allows me to find all possible pairs of square numbers including duplicates. We can also assume the array elements to be of positive integers only. e.g an array of {5,25,3,...
4
votes
2answers
72 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
2answers
65 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 ...
2
votes
3answers
67 views

PHP recreate array if it contains certain values

I have $fruits_arr: ...
2
votes
2answers
58 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 ...
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
105 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] ...
2
votes
1answer
116 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
3answers
87 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
91 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. ...
2
votes
2answers
87 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
106 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 ...
1
vote
2answers
56 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 ...
2
votes
2answers
54 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 ...
5
votes
1answer
86 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
1answer
86 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
2answers
113 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
127 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
52 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
1answer
72 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. ...
2
votes
0answers
42 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
53 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
118 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
77 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? ...
11
votes
3answers
887 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 ...
3
votes
0answers
86 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
52 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
42 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
48 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
465 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
1answer
62 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 ...