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

1
vote
1answer
14 views

Merge Sort Implementation in Java (that seems slow…)

I decided to write my own implementation of merge sort. Here is the code: ...
11
votes
4answers
1k views

Hackerrank “Sherlock Holmes” challenge

Watson gives to Sherlock an array: A1, A2, ⋯, AN. He also gives to Sherlock two other arrays: B1, B2, ⋯, BM and ...
0
votes
1answer
40 views

Storing array inside closure

Is storing array values inside of a closure considered to be bad practice? I having been trying to decide if I should just use a standard object with key value pair. This is not the method I am ...
5
votes
1answer
88 views

Special summation of integer array elements

I looked at this question and thought that I could find a much simpler way of doing this, here is the criteria that was given: My current task is to find a score from an array where the ...
6
votes
3answers
107 views

Convert dict entries to sets and lists

Can you please tell me if there is a better way to do this? ...
12
votes
5answers
1k views

Reverse words in a given String

I'd like this code to be improved Input string: codereview is awesome Output string: awesome is codereview My approach: ...
13
votes
4answers
628 views

Random name-picker with array

I created a program that picks a champion for a role on the game League of Legends using arrays and random numbers. Is there a quicker and more efficient way of doing this? There is one form that ...
1
vote
1answer
65 views

Finding Duplicates in Java

I am trying to figure out a way to make finding duplicates in Java more efficient. I started off with this: ...
2
votes
1answer
71 views

Generating sorted array in descending order

I have a method that generates a sorted array with random values in a given range. I wanted to make a method that does this but in descending order. The easiest way to accomplish this is to call the ...
4
votes
2answers
336 views
3
votes
2answers
53 views

in_array() in Go

This function's objective is very simple. It takes array and checks if val is a value inside of this array. It returns whether ...
8
votes
5answers
370 views

Randomly generating a sorted array

I'm writing a method that generates a random integer array that are sorted. It takes the arguments of min value, max value and the length of desired array. So for example the arguments with min val = ...
8
votes
2answers
286 views

Remove Empty String array from ArrayList

I am trying to remove empty a String array from ArrayList: ...
2
votes
1answer
49 views

Refactoring while-do into tail recursion with F#

I have a while-do loop nested inside a while-do loop in my program, due to it needing to iterate in two dimensions through an array of arrays, and originally my loop looked like this: ...
4
votes
1answer
56 views

Is this a good algorithm to unflat js objects?

I am dealing with a scenario where I get data in the following form: ...
0
votes
3answers
70 views

Linked list vs array performance for RemoveAt() function [closed]

I am trying to compare the RemoveAt() function performance in an array and linked list. For array: ...
3
votes
2answers
126 views

Shuffling array elements in C

This is an answer to this problem. Basically, given an array, swap the given number of elements in the array. The solution that came to my mind: since we always swap at least two elements, pick two ...
7
votes
2answers
310 views
7
votes
3answers
378 views

Ticket management system

I am building a ticket management system for a state server we use at work. Back end is node.js with multiple front ends. I am rewriting my back end to be more maintainable as the scope grows. For ...
7
votes
5answers
393 views

Checking if an array is sorted

I've come up with two ways to check to see if array is sorted and return true if it is. ...
5
votes
2answers
72 views

Array 2D pairwise function

I found myself in the need of a function to pairwise an array 2D so I created one: ...
3
votes
4answers
123 views

Returns values for a specific array and key

This code is intended to take an array and a key as inputs, and return an array of the values paired with that key. ...
7
votes
3answers
265 views

Index into array as if it is circular

The problem: Treat an array as if it is circular; out-of-bounds indices "wrap around" the array to become in-bounds. Current solution: ...
3
votes
1answer
94 views

Locating a bitmap inside another (larger) bitmap with F#

This is my firstish (heavily rewritten) go at the completed project that I've been working on with CodeReview assistance, so further advice is appreciated! See here, here and here for the past history ...
2
votes
2answers
177 views

Efficient way to iterate over elements of array for matching contents of another array

Using jQuery I'm trying to find an efficient way to iterate through an array excludeMe and check if elements from another array ...
7
votes
4answers
94 views

Use a Java Array like a List

I'm saving string values in an array one at a time so I cannot initialize the array with the values all at once. After I'm done with the array I need to pass it to another class that is expected a ...
5
votes
2answers
93 views

Initiating class objects and arrays

I have a class that always has 14 instances. I'm just wondering if there is a better or more effective way of doing this. In this class I also have an array that is filled by calling 4 functions ...
6
votes
2answers
183 views

How can I quickly find unique list items?

I use the loop-every-single-list-item approach to filter out unique elements in a given list, which tends to be very inefficient way as a list grow in size, or as function call frequency increases. ...
7
votes
1answer
153 views

Program to insert, search for and delete an element from an array

I'd like this code to be improved. ...
3
votes
1answer
52 views

Transforming a byte array into an array of byte arrays with F#

This code is intended to be used with an image manipulation library that I'm working on, and the goal is to take the raw byte[] data from an image, and transform it into a 2D array where each position ...
3
votes
2answers
90 views

Returning nested array with added key=>value

This works, but do I have to make a new array, result, or is there a way to just insert the field I need into each $key of the ...
8
votes
2answers
121 views

Finding the longest Collatz sequence cycle

I wrote a program to calculate Collatz sequences for initial numbers between 1 and a given integer i, then find the one with the largest cycle length. My code is ...
4
votes
1answer
107 views

Converting string array to string (and vice-versa) for storing via XML

I'm using XML to store data and I need to store a string array in it. The best way (that I can think of) to store a string array is by converting it to a single string. In order to do that, I'm using ...
7
votes
2answers
78 views

Program to find the element in an array

I'd like this code to be improved. ...
4
votes
2answers
88 views

Implementing write sphere of values to 3D array

The code below is sort of complicated to explain... It writes a "sphere" of data to a 3D array from the given 3D-Position outwards in a spherical shape based on the given radius and value to write. A ...
7
votes
3answers
278 views

Find two unique integers in sorted array

I have to write the following method: I have sorted array of integers and in this array every integer repeats twice, except two elements. I have to find these two elements. Input: 1, 1, 2, 3, 3, ...
4
votes
5answers
190 views

Search algorithm for specific values in a 3D array/matrix being super slow

I'm trying to create code that reads a text file (containing (double) numbers between 0 and 1) and filling up a 3D array/matrix (calling it matrix from now on) with ...
2
votes
1answer
46 views

Duplication Elimination Project [closed]

I am currently doing a project for school, and I am completely stumped. We are only on Chapter 8 of C# Development 1 and I have a question about the code. The project is: Use a one-dimensional ...
4
votes
1answer
54 views

Product of corresponding elements in 2 arrays

Given two arrays A and B, of length N and length k ...
4
votes
2answers
52 views

Dynamic array of Years

I wanted to make a dynamic select statement from this year to 10 years. This gets the job done, but I feel like it's a little much. ...
10
votes
5answers
621 views

Yahtzee game (using arrays and object classes)

As part of an assignment for my intro Java class (please bear with my beginner skill set), I'm working on a program for which a Die object class is used to play a Yahtzee game. An overview of the ...
4
votes
2answers
137 views

Searching for duplicates without any collection or sorting

I have written code which is easy to understand, but may not be efficient but will solve the purpose. ...
7
votes
3answers
173 views

Compare string with wildcard string

I have the following function to compare a string with a wildcard string (containing ? and *), as C# doesn't seem to have a builtin function to do it. ...
1
vote
1answer
79 views

Declaring arrays knowing their maximum size

I know the maximum array size is 6. So what is the best practice to declare an array? In the following code I used it like this: ...
8
votes
2answers
181 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? ...
4
votes
2answers
202 views

Finding the value 'n' in an array that has 'n' or more larger values

Given an unsorted array of integers, you need to return maximum possible \$n\$ such that the array consists at least \$n\$ values greater than or equals to \$n\$. Array can contain duplicate ...
5
votes
2answers
52 views

Finding the best matching block/patch in Python

I wish to locate the closest matching NxN block within a WxW window centred at location (x,y) of a larger 2D array. The code below works fine but is very slow for my needs as I need to run this ...
1
vote
2answers
76 views

Given suffix array and a pattern, search if given pattern exists

Given a suffix array for a word, check if a pattern (consecutive chars) exists. Example: A suffix array constructed for "ameya" should return true for "ame" but false for "foo" or false ...
7
votes
2answers
93 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. ...
5
votes
3answers
294 views

How to increase performance/speed of code that uses .Count() on Lists?

The Test PublicQuestion_ComplexTest is taking around 1600ms (1.6 seconds) to run, but used to take 92ms. I have a feeling this is because of recent code changes ...