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
2answers
50 views
Multidimensional dynamic array class using a continuous block of memory
The following code is designed to be a multidimensional array that works off of a continuous block of memory. It is designed to be able to be resized at runtime, but only when a resize is explicitly ...
3
votes
0answers
17 views
Loading text into an array when fields are in random order
This script reads records from a CSV file of customer names and addresses. The first record of the file is the header (field names); the fields could be in any order, and sometimes have different ...
2
votes
1answer
23 views
Importing data into Excel
Is there an easier way of importing data into an Excel array or other data structure? I've tried researching collections but I have found the documentation hard to comprehend.
MSDN
The code I have ...
7
votes
2answers
169 views
Let's play Rock, Paper, Scissors
I have written my first rock, paper, scissors project recently. I had to use a lot of if statements and System.out.println(); commands in the program. I am wondering what ways I could optimize my ...
3
votes
2answers
47 views
Queue resizing array implementation
After learning about linked list implementations of a queue I was asked to try a resizing array implementation. I'm looking for constructive criticism.
...
0
votes
1answer
48 views
Create new array by filter origin array
I'm getting an array and I needed to find a duplicate ID inside:
...
1
vote
2answers
74 views
Merge array of hashes, keeping duplicate values as arrays
I am working on a Ruby gem to pull data from the Wikidata API. The data is deeply nested, as it contains a lot of repetition.
I have written a piece of Ruby (sans Rails) code that enables an array ...
0
votes
0answers
19 views
Directory listing in Node.JS
This solution works, and I like having all the logic after the return.
The main purpose of this function was for use with other functions to return a file list:
...
3
votes
3answers
84 views
Find majority element in an array given constant external space
Given constant external space (yes no HashMap), how would you improve the following code (code-wise or complexity-wise with stress on the latter) to find the ...
-3
votes
0answers
23 views
0
votes
0answers
15 views
Converting from a madlib program using hashmaps to using 3 different arrays to hold the noun, verb, and adjectives
Using erb and Sinatra, I need to make an array of each variable that can be added in, [noun], [verb] and [adjective], allowing me to return the number of each there are and create the appropriate ...
3
votes
2answers
59 views
Duplicates in array elements and sorting
I've been given this little test exercise for an interview as php developer, and I'd like to hear from you if my solution is good (enough) or if the problem could have been solved in a better way. ...
9
votes
2answers
98 views
Min sub array size with a given sum
How can the time complexity of the following code be improved (assuming it's \$O(N^2)\$)? What about style and patterns?
This code is trying to find the minimum subarray size that adds up to given sum ...
4
votes
1answer
54 views
Allocating a contiguous block of memory for an array
I try to work with a contiguous block of memory, to create an array (2D) whose SIZE is not known at compile time (before c99) so no variable-length arrays are involved here.
I came up with the ...
0
votes
1answer
8 views
JavaScript 2D Grid Wrapper
I have written a simple wrapper for a 2D grid in JavaScript that allows me to resize the grid dynamically and I'd like to know if there's any way I can improve on my code.
Here is the code itself:
...
5
votes
2answers
50 views
Processing a sequence of additions and deletions
I am working on a program which manages a list, and must be able to insert new items, and delete ranges of items. I want the user to be able to specify the insertions and deletions in terms of the ...
3
votes
1answer
38 views
Serialize and deserialize n dimensional int array
I've made two symmetric methods which serialize an int array of any number of dimensions into an OutputStream, and read such an array from an InputStream. I was wondering if there is ways this code ...
0
votes
1answer
31 views
Condense JSON for bandwidth efficiency
JSON is quickly becoming the formatting standard of choice for quick, convenient, and reliable machine to machine communications. It is flexible and widely supported but it has some drawbacks when it ...
6
votes
10answers
448 views
Rotate an array to the right by a given number of steps
Recently, I encountered this coding exercise on codility and the idea is
A zero-indexed array A consisting of N integers is given. Rotation of the array means that each element is shifted right by ...
4
votes
1answer
54 views
Replacing multiple substrings in a string
Here are 2 functions defined that do the exactly same thing: take input a template (in which one wants to replace some substrings) and array of strings values (key value pair to replace, such as ...
2
votes
2answers
99 views
Simple TicTacToe game in C++
I just started learning C++, and this is one of my projects. It's just a simple 2-player (No AI) TicTacToe game that runs from the console. The project was to familiarize myself with arrays, so review ...
5
votes
2answers
81 views
Alternately taking elements from an array
Given the task of having to return an array that alternately takes elements from two arrays, what would be most Ruby way of completing the task? As of now, I have this code, but it doesn't feel very ...
0
votes
2answers
43 views
Finding the length of the longest streak of ones in any array
I need help reviewing my code snippet copied below.
The below code counts the number of continuous ones in a given array of Size 11.
...
6
votes
2answers
77 views
Populating an array with times with half hour interval between them
So for example, getTimes("12:00", "15:30"); should return:
["12:00", "12:30", "13:00", "13:30", "14:00", "14:30", "15:00", "15:30"]
The input parameters are always ...
4
votes
1answer
95 views
Generating an HTML table with colspan and rowspan from a one-dimensional array
I will be given the following input:
...
3
votes
2answers
62 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
1answer
64 views
Dynamic multidimensional arrays
My application needs Field objects, which encapsulate 1D, 2D or 3D gridded data. The number of dimensions and their size are known only at run time. Furthermore, I ...
0
votes
1answer
33 views
Counting distinct lists in a list
I'm trying to remove the duplicate from the list and count the list after removing the duplicates
...
3
votes
2answers
54 views
Assigning entire column of data to specific column of an array in VBA
The below code I have written is to allow me to Sum the results data for every year from 1 to 1000 over a range of 5000 locations. although a 1000 years seems extreme, for the application I am using ...
1
vote
1answer
41 views
Concat strings from Object or Array
How would you merge these two functions into a single more generic function?
...
0
votes
0answers
25 views
Prefetch in ARMv7
I have to implement Khatri Rao product between 2 matrices in C. Mathematically this is a column major access of data and I can not change that. But if I use preload ( PLD instruction in ARMv7 ) to ...
6
votes
1answer
27 views
When values are pasted into a bigger range, the values should be repeated as needed to fill the range
I am currently working on a project, and I just wrote a piece of it that requires a lot of array manipulation. Given a text input I want to expand it to fill the number of rows and columns I have. I ...
3
votes
1answer
37 views
Slicing a big NumPy array
I have a function that takes a four-dimensional NumPy array M and, for each value i of its second index, takes all of M without the i-th "column", evaluates the product over all other columns, and ...
0
votes
2answers
59 views
Effective Python 2/3 two-dimensional array initialisation
Recently I noticed that the idiomatic python two-dimensional array initialisation is extremely slow. I am wondering, is there a good, proper way of doing this simple task fast? Also, are those two ...
2
votes
1answer
47 views
Expanding pixels in an image
Custom class Image takes a 2-D array of 0's and 1's upon initialization. Method transform returns a modified array by modifying 0's adjacent to a 1, such that
...
1
vote
2answers
36 views
6
votes
4answers
131 views
Finding the longest sequence of positive numbers in integer array
I am preparing for a coding interview and I have the following questions:
Find the biggest positive number sequence in the Integer Array.
If Input is ...
1
vote
1answer
26 views
Python list “commander” (modify a list with user commands)
I made a program that can modify a list using commands that the user enters.
The commands that are supported are (used from actual program):
...
2
votes
1answer
46 views
Find the contiguous subarray within an array (containing at least one number) which has the largest sum
Interview Q: Find the contiguous subarray within an array (containing at least one number) which has the largest sum.
For example: Given the array [-2,1,-3,4,-1,2,1,-5,4], the contiguous subarray ...
5
votes
1answer
40 views
Three stacks in a single array
I have implemented three stacks in a single array in Java. Any advice on object oriented design, coding structure, logical part or any sort of advice would be appreciated.
...
3
votes
3answers
183 views
Building prefix tree from dictionary, performance issues
I'm trying to build a prfix tree. So, using the following dictionary 'and','anna','ape','apple', graph should look like this:
I've tried 2 approaches: using ...
5
votes
1answer
73 views
Computing the total different between a pixel and its neighborhood
I have C++ code which written for mex in MATLAB. It used to compute the total different between a pixel and its neighborhood (8 neighborhood in my code). The code ran and gave me an expected result. ...
2
votes
4answers
85 views
2
votes
1answer
44 views
LeetCode Rotate Array
I have started learning Java and was trying to solve some easy problems from different websites like HackerRank and leetcode.I am relatively new to programming so please don't mind if this is too ...
8
votes
1answer
110 views
Simple Conway's Game of Life implementation in Java
I wrote a simple implementation of Conway's Game of Life in Java using 2 arrays and for loop and used StdDraw library for plotting generations.
It turned out that ...
0
votes
1answer
35 views
Change non-diagonal surrounding elements in a 2-D array
I'm a beginner working through an exercise on ruby arrays. Given a two-dimensional array with 0's and/or 1's, it should return an array with the non-diagonal surrounding elements of 1 changed to 1 if ...
0
votes
1answer
83 views
Custom Dynamic Array
Pretty simple class but just want to make sure I've approached it correctly.
...
3
votes
1answer
71 views
Generic variable-size array
As stated in the tags, I'm a beginner to C. This code implements a dynamic array (List in .NET, vector in C++, etc) for any ...
-3
votes
1answer
70 views
Nim Game with Arrays [closed]
I am suppose was to incorporate arrays in my NIM game java code, so that we can allow the user to decide on how many heaps are in play. I am stuck and have no clue how to do so.
Heap Class
...
0
votes
2answers
46 views
Create an array with at least a given number of bits
I use this declaration for an array which must contain a bit for every minute in a day:
...