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
4answers
40 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
30 views
2
votes
1answer
25 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 ...
-2
votes
0answers
30 views
Hacker earth Challenge - Number of Interest [closed]
I am facing a rather humiliating problem. There is a challenge which I have solved but when I submit the code I am getting a score of zero. But it seems to be producing correct output when I am ...
3
votes
2answers
43 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
33 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
130 views
2
votes
3answers
76 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
64 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
1answer
75 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
32 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
418 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
86 views
0
votes
1answer
20 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
320 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
354 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
63 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
100 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
72 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
168 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
177 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
69 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
58 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
354 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
88 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
36 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
99 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
65 views
1
vote
0answers
16 views
Complete date ranges for two years
I have array contents with some date ranges, fetched from the database:
...
3
votes
1answer
33 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
68 views
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
134 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
127 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
254 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
644 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
69 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 ...
8
votes
3answers
381 views
Project Euler #2 (Fibonacci Sequence)
Challenge: The Fibonacci sequence is generated by adding the previous two terms.
By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8,
13, 21, 34, 55, 89.
Consider a ...
8
votes
3answers
173 views
Computing the relative magnitude of the values in one double array to another
An interview question I received:
You are given two unsorted lists of positive doubles
x contains the results from experiment 1
...
1
vote
1answer
99 views
Are nested foreach loops to compare two multidimensional arrays efficient in PHP?
I've got the following PHP code, which is taking a search term, and checking if any of the search terms could be or could have a nickname.
...