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

66
votes
15answers
4k views

Searching an element in a sorted array

I was applying for a position, and they asked me to complete a coding problem for them. I did so and submitted it, but I later found out I was rejected from the position. Anyways, I have an eclectic ...
23
votes
7answers
2k views

is_numeric_array() is missing!

I found that in PHP (or I probably can't find it) a proper is_numeric_array($array) function is missing. So I created one. The problem is that I don't think it's ...
19
votes
6answers
1k views

How can I make this mess of Java for-loops faster?

I'm trying to find all the 3, 4, 5, and 6 letter words given 6 letters. I am finding them by comparing every combination of the 6 letters to an ArrayList of words ...
19
votes
6answers
5k views

Guessing a unique 4 random digits number

I've created a simple game, in which the user needs to guess 4 digits number between 0-9, generated randomly using Random() Each of the 4 digits are different from ...
16
votes
10answers
2k views

Find all the missing number(s)

Recently I've attended an interview, where I faced the below question: Question: "There is an sorted array. You need to find all the missing numbers. Write the complete code, without using any ...
14
votes
6answers
1k views

Array whose values are the product of every other integer

I was asked the following interview question over the phone: Given an array of integers, produce an array whose values are the product of every other integer excluding the current index. ...
13
votes
4answers
512 views

Finding the sub-array with the maximum sum - my approach

This is the code I ended up with that implements the approach I described in a recent answer to another question about the same problem The basic idea here is to not loop through more things than ...
13
votes
8answers
19k views

Java function to read a CSV file

I have a java function that reads a csv and returns its content as a Vector<Vector<String>>. The function seems to work as I need it, but my gut ...
12
votes
3answers
2k views

Reverse a String in Java

Here is the code for the CString class that I created. ...
11
votes
4answers
311 views

Why is this code so much faster (relatively) in IE7?

Here's some code that I ran through jsperf to assess its performance. The first test (named EvalLengthBefore++ in the images below) is the way I would consider normally looping through the elements of ...
11
votes
4answers
364 views

Finding subtuple in larger collection?

I've got a flat array of < 1000 items and I need to find the indices of a smaller tuple/array within the array. The tuple to find can be a varying length (generally between 2 and 5 items, order is ...
10
votes
4answers
492 views

Find byte[] in byte[] with Java

I made a search method because I want to use binary data like PNG files. The point of this is to be able to find strings like IEND in a PNG file. I think it works ...
10
votes
3answers
223 views

Displaying random quotes from an array

Is there anything that I could have done better in this code? ...
10
votes
2answers
2k views

Word count program in Java

I am trying to write clean code in Java for reading text of any size and printing the word count in ascending order without using Java collection framework. For example, given the following input ...
10
votes
4answers
10k views

Removing duplicate values from an array

Here is my code for removing duplicated values from an array. I think I tested it with the most possible cases. Any suggestions or bugs? ...
10
votes
3answers
490 views

Writing a function to add or modify an existing object inside an array

I have an array of objects. Each object has two properties, id and quantity. I wrote a function to add an object to the array. ...
10
votes
1answer
149 views

Faster way to find maximum deviation?

So, it was a part of my coding challenge and the last one, but I failed because it failed to yield a result in two seconds for some of sample inputs (out of six samples, three passed but three failed ...
10
votes
2answers
177 views

Best way to handle elements of a private array

This feels like a simple question, but I'm wondering what the best way would be to manage the elements of a private, fixed-size array. Context: I'm making a simple particle engine, and my ...
10
votes
1answer
379 views

Bubble Sort in C: Array vs Linked List

A few weeks ago I posted a code review of a linked list so I decided to implement bubble sort on my journey of learning C. Here is the referenced linked list library, though this isn't really what's ...
10
votes
2answers
111 views

Improve performance of math function applied to arrays

This block of code is already somewhat optimized thanks to some answers given over at Stack Overflow. In the last question I made (Improve performance of function without parallelization) the code was ...
10
votes
1answer
86 views

Pascal Triangle program in C

I've created a program to calculate Pascal's triangle: ...
9
votes
5answers
1k views

Repetitive code driving me crazy!

Ok, So first I must say that everything I know about coding I have learned on my own in my spare time so bear with me if my code is primitive, but please, I am open to any comments to make me ...
8
votes
4answers
2k views

Finding all indices of largest value in an array

I have the following code that gives me the indices of an array's largest value: ...
8
votes
4answers
407 views

Dynamic array of structs in C

Based on some code on internet, I implemented a dynamic array of structures in C. I am really interested in some feedback on this. Maybe there are some places where it can cause memory leaks or ...
8
votes
2answers
149 views

Min and Max initialization

Is it a good practice to initialize the max to -100000 and min to 100000? Is there any other way to initialize both min and max to 0? ...
8
votes
2answers
321 views

Rotating array members

I had a situation when I needed to move all array elements in circular fashion. When I say this, I mean: 0 1 2 3 1 2 3 0 2 3 0 1 3 0 1 2 So the array: ...
8
votes
1answer
2k views

A boolean expression parser, written in Java

I was trying to write some of the Haskell list functions into Java, and I realized that one of the key strengths for many of the functions was the ability to pass in a boolean expression. I decided to ...
7
votes
6answers
555 views

Python address index +1 with list comprehension

Task from CodingBat: Return the sum of the numbers in the array, returning 0 for an empty array. Except the number 13 is very unlucky, so it does not count and numbers that come immediately after ...
7
votes
4answers
498 views

Find the subarray with the max sum

In an interview I was asked to solve the following problem: find a subarray with max sum I have written a piece of code for the same. I need your help in reviewing this code. ...
7
votes
3answers
538 views

Stack implementation using an array

I am trying a stack implementation using an array. I want to know if this approach is OK or if there is a logical problem. This program is working fine. ...
7
votes
2answers
655 views

Fastest way to cut an array into two arrays at a particular index

Suppose I have the array: double[] arrayToCut = new double[100]; for(int i = 0 ; i < 100 ; ++i) { arrayToCut[i] = Math.random(); } My objective is to end ...
7
votes
2answers
87 views

Output in one window

Can anyone give me feedback please? I used what I have learnt so far, mainly methods, loops and arrays. I would like you view based on these topics, however, comments on how to improve are welcome. ...
7
votes
2answers
410 views

Please review this C-style array class

I often use C API's in C++ that force me to use C-style arrays. I got sick of constantly using a dynamic vector with &vec[0], so I wrote this C-style array ...
7
votes
2answers
127 views

Generate permutations with symbols

Goal: Create a combination of emails based from inputted first name, last name, middle name, and a domain. Add in common separators. Then I'll check which one is correct with the rapportive API. This ...
7
votes
2answers
259 views

Merge some child values back into the parent multidimensional array

This is a wonky PHP function I came up with to merge some select values from child arrays into the original. It could really use some help simplifying / making it more elegant. Is there a built-in ...
7
votes
2answers
1k views

A blocking buffer manager to provide segments of a byte array

Since asynchronous operations (like Socket's Begin*-End* pairs and ...
6
votes
5answers
4k views

Comparing string arrays

My code does what I need it to do, but I think I am missing the "right" way to do this with comparing the arrays. Essentially what I need this to do is compare a textbox entry against two different ...
6
votes
4answers
380 views

Sum of subset of 5 numbers equals 0

I have a task to print all zero subsets of 5 numbers, input from the console. I have succeeded in implementing a working code, but it seems it is quite complex (it is like inception) and if the count ...
6
votes
4answers
3k views

Anagrams for a given input

This question is the first draft, my new revised code is here: Anagrams for a given input 2.0 Here is my code that I wrote, which basically lists the anagrams for a given input. I did this by ...
6
votes
2answers
4k views

Read an input text file and store the tokens in 2 different arrays

I am very new to Java so please ignore if there are obvious mistakes. If my question seems redundant then please guide me towards the correct link. However, I have surfed enough in order to find the ...
6
votes
4answers
3k views

Getting the largest element in an array using recursion

Any suggestions on how to make this code more efficient? ...
6
votes
2answers
1k views

Find all single elements in an array

I am interested in printing all numbers that do not have a match in an array. Example: 1,3,4,5,3,4,5,5,6 result 1,5,6 Please ...
6
votes
2answers
414 views

Generating a list of alternatively positioned odd and even number out of an array of unsorted integers

I had an half an hour interview with Microsoft for an intern position. I was asked to generate a list of alternatively positioned odd and even number out of an array of unsorted integers. I guess it ...
6
votes
2answers
373 views

Is there a way to optimise my Perlin noise?

I just started using Perlin noise a few days ago, and the results look quite good. But it takes over 3 seconds to calculate and draw a 1024x1024 bitmap of said noise. I use an array of 1024x1024 to ...
6
votes
2answers
153 views

Inversion of an array that contains indices

I have an array of length n that contains numbers from 0 to n-1 in random order. I now want to "inverse" this array to one that where index i corresponds to the location of i in the source array. ...
6
votes
2answers
109 views

Return index of array where sum first passes n

I have an array of integers and a number n. I want to sum the elements of the array and return the index where the sum passes ...
6
votes
2answers
274 views

Simplification of byte array comparison algorithm

I have an algorithm that evaluates in input byte[] with a source byte[]. Several conditions can be encountered: Match found No ...
6
votes
1answer
114 views

Is there a for-statement I can use to subtract elements in my 2-D in order to make my code more efficient and less-cumbersome?

This code works 100%, but I am trying to see if I can use a for-statement to make my second method less-cumbersome and more efficient instead of making so many ...
6
votes
2answers
6k views

Trying to build a student grading array program

I have a program to calculate and show the grades for 4 students and 3 tests. I want to calculate the average for each student, the average of the test scores for each test, and the average of the ...
6
votes
1answer
5k views

Find all subsets of an int array whose sums equal a given target

I am trying to implement a function below: Given a target sum, populate all subsets, whose sum is equal to the target sum, from an int array. For example: ...