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.

learn more… | top users | synonyms

4
votes
0answers
41 views

Mapping arbitrary Int values to a linear index space

This is part of a growing "primitive" tools collection here on github, and is the initial use-case for the IntArray for review here. Often, when processing data, you encounter unique values that you ...
6
votes
2answers
191 views

Finding pairs of numbers within A that add up to N

I am working on an interview question from Amazon Software Interview: Given an integer N and an array of unsorted integers A find all pairs of numbers within A which add up to N I have a working ...
9
votes
2answers
72 views

Using 2D arrays to make more efficient sequential storage

This code is part of a growing "primitive" tools collection here on github Use Case Consider: ...
0
votes
0answers
11 views

Circular Vector Implementation of sorted priority queue [closed]

There's this weird error that should be in my removeMin() function. Inserting items into a SortedPQ object seems to work just fine but attempting to remove any items (I used a for loop in my main ...
1
vote
4answers
48 views

Finding the second largest element of large input sets

I have a problem where I need to find the second maximum element of the user inputs. It's an online practice problem and I can't figure out why the server responds back with a Non-Zero Exit Code error ...
0
votes
0answers
32 views

Loop to obtain sublists of arraylist [closed]

I have the following code: ...
2
votes
1answer
30 views

Reading and Converting XML File to Array

I'm using WordPress ( PHP Based Platform ) and I'm trying to read an external XML File, convert it into a usable array, then compare two arrays - one from the xml file and another from an options ...
3
votes
2answers
44 views

Transform a string into an array based on grouping rules

I've got a simple spec for defining character sets, ranges, or wildcards. I'd like to take the string and appropriately create an array based on these rules. I have a solution but I'm sure there is a ...
3
votes
1answer
37 views

Dynamic array implementation

I would like to use code below for general purpose dynamic array implementation in my future code. How does it look? array.h: ...
10
votes
4answers
137 views

Lottery number generator

...
2
votes
3answers
79 views

Returns an array of all inputs with specified name

I've made a nice little function to return a NodeList array containing all the inputs that have a specified name attribute: ...
0
votes
3answers
73 views

Finding all integers in an array with odd occurrence

I am doing an interview exercise problem from here. The problem is to find "all numbers that occurred an odd-number of times in an array". Here is my high level psuedo code thinking: Construct a ...
4
votes
2answers
96 views

Binary search that returns bitwise complement of missing index

While re-writing some old JavaScript code to better handle large arrays, I ended up writing my own binary search method. I found many examples of binary search methods written in JavaScript, but all ...
0
votes
0answers
35 views

Passing an array in a hyperlink

Maybe this is fine the way it is, but it seems messy. Basically I have dynamically generated HTML that will display a list of songs in a given folder. Each song has an ID, and I want to add a button ...
7
votes
4answers
425 views

Reversing the lines of a file

I am trying to reverse the lines of a file by reading the file through an array. Is there a more efficient and quicker way of achieving this? ...
6
votes
2answers
96 views

Choosing a random flat color

I have a big array of custom flat colors with perhaps 100 lines: ...
0
votes
1answer
21 views

Bridge Transport - contest practice

I'm practicing for a contest by doing some of the older problems, and I was wondering if there are more efficient ways of doing this or if I'm not following any coding conventions. Most importantly, I ...
8
votes
3answers
326 views

Two sets came to an intersection

Challenge: Print set intersections. Specifications: Your program should accept as its first argument a path to a filename. Each line in the file is a test case. Each test case contain ...
8
votes
4answers
361 views

Calculating range of ArrayLists

I have written this method which calculates the range (max - min) of an ArrayList. I have two for loops each for a different ...
3
votes
1answer
67 views

Stack with Array

Just coded up a simple Stack using an Array in Java for practice. Other than the lack of JavaDoc (still need to learn that part), did I cover all the bases? ...
4
votes
3answers
101 views

Aggregate array values into ranges

In five minutes I made a pretty ugly looking function. Can you help before I have to commit the code into history? Requirements: I would like a function that takes an array of numbers, and ...
2
votes
4answers
76 views

Concatenate two arrays generated randomly

I have written the code to concatenate two arrays . Please let me know of any loopholes in the written code. ...
15
votes
4answers
1k views

Duplicate like a weapon, arrays like heaven

Challenge: Find the duplicated entry. Specifications: Your program should accept as its first argument a path to a filename. Each line in this file is one test case. Each line ...
3
votes
4answers
170 views

Count the ways to partition an array into two equal sets

I need to count the number of ways to partition an array into two contiguous arrays such that those arrays contain exactly same set of items. Suppose ...
1
vote
1answer
31 views

Merging website info into an array

I'm scraping a title and a link from a website and placing them in a single array. The $i variable seems a bit wrong to me, or is it perfectly fine? ...
1
vote
1answer
53 views

Party Invitation - Trimming the Invitation List

I am learning Java right now and am coding some simple programs to practice. Right now, one of my for loops has an inelegant way of ending the loop. I was wondering ...
5
votes
1answer
186 views

Listing the first 100 prime numbers

I thought of this implementation, and I want to get feedback from you.. what design would you use for printing first 100 prime numbers? I used the fact that, if the number is not divisible by any ...
3
votes
2answers
73 views

Removing duplicates from an array

I recently wrote this JavaScript algorithm for removing duplicates from an array as part of a job interview process, but was turned down for the position after submitting the code. I didn't receive ...
3
votes
2answers
59 views

Sort ArrayList in a better way

I have a list of categories (in this example I used String but in my project I have a model) which must be sorted like this: on top we should have 2 categories ...
4
votes
1answer
373 views

Polyglot array_extend() function for Javascript and PHP

This is a polyglot function I've made out of fun. The goal is to grab n arrays (or Javascript Objects) and 'extend' them in ...
2
votes
3answers
92 views

Summing data from two arrays, grouped and sorted by date

I have multiple multidimensional arrays that each have the same structure with different lengths. ...
6
votes
3answers
238 views

Reading, echoing, and returning integers in an array

I was wanting some clarification on my code, as I am new to pointers in C. I am trying to return an array from a simple function just so I can understand exactly what it is that I'm doing. Here is ...
4
votes
1answer
43 views

Rebase values in an array to match the chart scale

I have 2 long[24] arrays. Both of them contain values for each hour of a day. One of them has hit count and other queue times. Now queue times in ms are 5 digit ...
3
votes
1answer
37 views

Java CharSequence iteration

A project I am working on requires me to check the first character of an input string, to determine if it is a numeric character. I have developed the following code: ...
2
votes
3answers
102 views

Jolly jumper sequence

Another challenge from CodeEval that's causing me great pain... Trying to find out if a sequence if a Jolly Jumper, which is A sequence of n > 0 integers is called a jolly jumper if the absolute ...
2
votes
2answers
154 views

Is there some way of taking advantage of code reuse in this example?

I am implementing a set, using an array as the backend. Here is how I declared it (and some method implementations): ...
1
vote
2answers
72 views

Print all combinations

Question: ...
1
vote
0answers
17 views

Complete date ranges for two years

I have array contents with some date ranges, fetched from the database: ...
3
votes
1answer
34 views

Finding candidate with the most matching values

I haven't coded all winter, and it seems like everything I learned about efficiency from my data structures class leaked out my head. I was wondering if I can get some help in making my code less ...
1
vote
1answer
50 views

C++ Readable serial constant range counter [closed]

What I am asking here is about code readablity. Consider the following code: ...
3
votes
0answers
69 views

any that can hold arrays

I've tried to make a better any than before: ...
1
vote
1answer
54 views

Faking a pass method when building an array

Ruby doesn't have a pass method to 'do nothing' the way Python does - if I want a ternary statement to do something on true, but nothing on false (as in the code below) is it bad practice in Ruby to ...
4
votes
2answers
141 views

Check if array A contains all elements of array B and vice versa irrespective of order

I am trying to check if an Array A contains all the elements of Array B and similarly ...
3
votes
3answers
140 views

Find intersection of two arrays without duplicates

A = [9, 1, 4, 2, 5] k unique integers B = [3, 1, 8, 7, 6, 5] n unique integers Intersection => [1, 5] Find an algorithm that uses \$O(1)\$ space (the space used by the return variable is not ...
4
votes
3answers
256 views

Find, on a sequence of size L, the number that appears more than L/2 times

Yes, yet another challenge on CodeEval! This one has the purpose of finding the major element of a sequence: the element which appears in a sequence of size L more than L/2 times. I have this: ...
4
votes
1answer
39 views

From object to array with revert and regroup

Basically, I need to regroup keys by values from an object to an array An example worth a thousand words in my case, as I don't know how to clearly explain my problem. Here is my input object: ...
4
votes
2answers
44 views

Find if an array is arithmetic or geometric

This seems to be working fine. I am pretty sure there is a better way to do it. How can my code be improved performance-wise? The main thing bothering me is the nested ...
2
votes
1answer
63 views

Road tax data parser

I'm making a data parser for road tax data (costs) which parses a JSON file with all weird variable names, which the customer gave me. The costs are different on each vehicle type. The costs at some ...
7
votes
3answers
646 views

Find the greatest number in an array

I created a simple program in C and I want to hear your opinions. The program reads a .txt file that contains lines of numbers. The first one has one number N and the second one has N numbers as the ...
1
vote
1answer
70 views

Count the accumulated rainfall in a 2D mountain range

Challenge: Count how much rain will be collected in the valleys between the peaks of a mountain range in a 2D world. The mountain range is defined by a single array of positive ...