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.
2
votes
1answer
27 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?
...
-2
votes
0answers
16 views
What is the logic error in the given NQueen algorithm? [on hold]
I wrote the following code for NQueens. But I end up with wrong answer. Could some one help me find the error in this?
...
4
votes
2answers
64 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 ...
1
vote
4answers
60 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
3answers
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
147 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
29 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
41 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 ...
4
votes
1answer
147 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
55 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
50 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
285 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
81 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
231 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
36 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
31 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
96 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
62 views
1
vote
0answers
13 views
Complete date ranges for two years
I have array contents with some date ranges, fetched from the database:
...
3
votes
1answer
32 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
46 views
C++ Readable serial constant range counter [closed]
What I am asking here is about code readablity.
Consider the following code:
...
3
votes
0answers
66 views
1
vote
1answer
48 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 ...
3
votes
1answer
100 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
105 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
252 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
38 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
59 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 ...
6
votes
3answers
639 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
67 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
352 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
169 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
78 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.
...
5
votes
2answers
252 views
Method to convert String to int array
I was working on a suggestion for this question, but the method, I would've suggested the OP do something similar to, seems a bit convoluted.
It's supposed to take a String input and return an array ...
2
votes
2answers
54 views
Ordering Gallery images by custom order
I wrote some code a few weeks ago, to take a string similar to
seq[]=8&seq[]=7&seq[]=5&seq[]=1&seq[]=4&seq[]=3&seq[]=6&seq[]=0&seq[]=2
and put it into a gallery, ...
2
votes
1answer
93 views
Solution to the CodingBat Array-3 [fix34]
I was studying for arrays from coding-bat and encountered this:
The question is: (fix34)
Return an array that contains exactly the same numbers as the given
array, but rearranged so that every ...
2
votes
1answer
55 views
Efficient byte sequence detection
I seek the assessment of which code block is more efficient in Java at detecting the byte sequence of
00 00 00 01
and
...
3
votes
1answer
75 views
PHP associative array with two properties
I'm moving a system over to PDO and since the queries are parameterized, I need to specify both the type and value of each parameter when preparing them.
Right now I have a ...
6
votes
1answer
72 views
Reading integers from a file and counting the length of a descending subsequence
I had a school project to solve, which I did. The basic focus of the project was to create the simplest code possible to solve it. This topic was created just to ensure if I wrote the code correctly.
...
1
vote
1answer
37 views
Efficiently consolidating an array of objects
In my program, I'm getting Facebook objects and using temp to display on a separate screen how many unread messages they have. However, we have since decided to ...
0
votes
1answer
29 views
Convert Array CSV to Object using Header
Takes the first array in the array and uses that to set the properties of an array-object.
...
7
votes
7answers
897 views
Given an array of integers, return all pairs that add up to 100
I was recently given this programming challenge on an interview, and I decided to use javascript to solve it. I did, but I'm not happy with my implementation. I can't help thinking there must be a ...
3
votes
3answers
143 views
Find the missing number in a array
I'm working on a personal project to practice my programming skills and I came to this problem. I tried to create a program that will find the missing number in a array.
I'm looking forward to ...
10
votes
3answers
505 views
Coding multiples that equal 100
The objective was to see what numbers can be multiplied to equal 100.
Example:
1 x 1 = 1 //no match
5 x 20 = 100 //match
The objective (as I'm learning) was ...
5
votes
1answer
66 views
VHDL mux in need of generics
I've built a multiplexer which takes 2 inputs: one array of std_logic_vector and one std_logic_vector to select the correct ...
5
votes
2answers
59 views
Is it ok to add a static method to the IEqualityComparer implementation?
Linq methods like Distinct need IEqualityComparer object. But sometimes I just compares two objects and to create Comparer instance for that is seems redundant. So it would be nice to use static ...
3
votes
1answer
95 views
Using std::array to implement variadic construction of class with list-of-self as subclass
I have a situation with a base class for whom a container of itself is a subclass. So a Block of Item has various ways in which ...
4
votes
3answers
218 views
Initializing a multidimensional with many default values
I need to create a \${n} \times {n}\$ multidimensional array filled with default values.
Right now, I'm using this code:
...