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.
6
votes
2answers
3k 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. ...
14
votes
1answer
29k views
Snake game using PyGame
I wrote a simple Python snake game which is about 250 lines of code. Can someone give me some advice on how I can refactor/make it better?
game.py
...
4
votes
4answers
441 views
Creating an array that loops out on the frontend - Don't Repeat Yourself?
Entire Code Here
Don't repeat yourself
I know of the "Don't repeat yourself". Still it's getting messy in some places. The code below contains three blocks of code.
They are similar in some ways ...
22
votes
7answers
5k views
Finding words of different lengths given six letters
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 ...
14
votes
2answers
162 views
Python ASCII-Art Table
As a part of a console utilities module, I created a function that takes a table in the form of an array of arrays, and generates an ASCII table with the given contents.
I've also added the options ...
4
votes
2answers
156 views
Find sum of number of times that each character of source occurs in the target
I wrote the following code in response to this question "find sum of number of times that each character of source occurs in the target", is there any better solution for it?
Analysis
...
2
votes
2answers
176 views
Finding number of number pairs with given difference [closed]
pairs() is a function which returns the total number of combinations whose difference is k.
...
115
votes
16answers
17k 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 ...
16
votes
2answers
67k views
19
votes
3answers
23k views
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 begins ...
22
votes
8answers
25k 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 ...
12
votes
2answers
42k views
Fastest way to iterate over Numpy array
I wrote a function to calculate the gamma coefficient of a clustering. The bottleneck is the comparison of values from dist_withing to ...
18
votes
4answers
14k 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:
...
11
votes
5answers
560 views
FiniteArrayQueue type with interface and unit tests
Doing some exercises on basic data structures, I learned about queues, and decided to roll my own to better understand how a basic queue can function. As the name indicates, this Queue is made from a ...
8
votes
4answers
11k 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
4answers
3k 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
1answer
934 views
Simple multi-dimensional Array class in C++11
The new version of the code can be reviewed in Simple multi-dimensional Array class in C++11 - follow-up.
The following code implements a simple multi-dimensional array class (...
0
votes
2answers
2k views
Review implementation of stack by using array in C [closed]
This question has become long after many updates. Click here to go down.
I have implemented stack using arrays in C. Please give me suggestions on how to improve it. The purpose of writing it is ...
17
votes
4answers
2k 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 ...
11
votes
1answer
181 views
Array-like container for uints shorter than 8 bits
Follow-up: Array-like container for uints shorter than 8 bits (Rev 1)
First of all: yes, I need this kind of array to generate data for a piece of hardware, and it must be stored and manipulated ...
8
votes
7answers
10k 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 ...
8
votes
5answers
11k 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.
...
7
votes
3answers
208 views
Simplified implementation of std::vector in C++
I implemented a simplified version of a C++ std::vector/ArrayList learning from this link. From it, I tried to write an ...
7
votes
2answers
211 views
Array-like container for uints shorter than 8 bits (Rev 1)
This is a follow-up to Array-like container for uints shorter than 8 bits
In short: The PackedBitfieldArray should be a kind of container for packed (unsigned) ...
4
votes
2answers
96 views
DoublingQueue in Java
Inspired by this CR question, I decided to create my own queue! If you guys see anything taboo or have any improvements, please let me know. Ultimately I want it to be feature rich and bug free, with ...
3
votes
2answers
1k views
Optimizing unboxed array operations in Haskell
Consider this simplified code which successively permutes array elements:
...
2
votes
1answer
320 views
Simple multi-dimensional Array class in C++11 - follow-up
Last week, I posted this question in order to get some comments and critiques on a simple implementation of a multidimensional array class -- hyper_array::array ...
10
votes
2answers
572 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:
...
8
votes
3answers
6k 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:
...
6
votes
2answers
173 views
Deca dimensional ascending and descending array sort function
Some folks told that a two-dimensional array can solve almost all the problems, but let me disagree with that. That's why I made this Deca dimensional array sort function. The array must be ...
6
votes
2answers
125 views
Weaving an array
In preparing this answer, one of the components was an algorithm to rearrange a sorted array in a particular way. To put it succinctly, here's the problem description:
Given an array \$A\$ with \$...
6
votes
2answers
12k 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 ...
5
votes
2answers
4k views
Copying from sheet to sheet if column headings match
Basically, I have three sheets in my workbook where only the second and third worksheets are being used. I want to copy columns from the second sheet to the third sheet only if the column headings ...
3
votes
2answers
198 views
Using Array to store calculations in VBA
I have the following VBA code, which works perfectly well to calculate "q"
However, the code is very slow and that is due to the large number of q's being calculated (roughly 7.2m q's are being ...
2
votes
3answers
85 views
Writing a particular column of a two-dimension array to a worksheet
I had some great feedback on my code previously here and I was hoping that I could get some further help with writing a column of the array to the worksheet.
I have an example here where I write one ...
1
vote
0answers
90 views
List interface implementation
After following the comment from greybeard,
Below is the design for given first phase of implementation,
Code directory structure,
...
0
votes
4answers
1k views
My own method for sorting numbers in array
I've written some method for sorting asc and desc numbers in array. All I want to know is this good logic, and is there a space for improving this code?
...
22
votes
2answers
424 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 ...
18
votes
3answers
2k views
Project Euler #1 in PHP
The code below works & as far as I can tell the result is correct. Would you please review and let me know what I could have done better?
I tried to use variables as much as possible, that way it ...
11
votes
1answer
742 views
Finding maximum deviation
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 for ...
10
votes
2answers
112 views
Creating a pseudo Pivot Table / Database using a 4-D array
Why am I not just using a Pivot Table / Database?
a) I've never ever used either before. And I don't have time to learn how before this project needs to actually be finished.
b) The final output ...
8
votes
4answers
8k 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
5answers
2k views
Count the number of unique elements in a sorted array
Write a method named numUnique that accepts a sorted array of integers as a parameter and that returns the number of unique values in the array. The array is ...
7
votes
3answers
8k views
Find elements occurring even number of times in an integer array
I came across an interview question, which is like this:
You have an array of integers, such that each integer is present an odd number of time, except 3 of them. Find the three numbers.
I tried ...
7
votes
1answer
97 views
Associating degrees with notes of scales
I have a JS file that creates an object with notes from a music scale when given a key (aka tonic/ note). The code works and does what I want it to do. I need a critique on the way it's written, what ...
7
votes
3answers
373 views
A Java subclass of ArrayList that supports rotation in constant time
(See the next iteration.)
I have subclassed java.util.ArrayList in order to be able to "rotate" it in constant time simply by moving a finger index. See what I ...
6
votes
3answers
2k views
Dynamically-expanding array in C
I'm learning C, specifically OOP in C. As practice, I wrote a dynamically-expanding array.
dynarray.h
...
6
votes
4answers
15k 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
11k views
Binary search for inserting in array
I have written a method that uses binary search to insert a value into an array.
It is working, but i would like to get a second opinion to see if i didn't write too much code for it. aka doing same ...