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
3answers
29 views

Extract subarray of elements that appear after the last occurrence of “4”

I am doing some challenges, and in one challenge given a non-empty array of int, I am to return a new array containing the elements from the original array that ...
0
votes
0answers
15 views

Xcode: Initializing a big static array

I have a card-based iOS app that uses a sizable static array of cards. Each card has several properties, mostly strings, numbers and boolean. The first version of this app had 3-4 properties. The ...
1
vote
0answers
22 views

Comparing two arrays and printing results as a collection of a class

This is really my first time using a class and I originally wrote it without the class and without refactoring. This is to take two inputs (csv), place the data in arrays and then compare the arrays. ...
1
vote
0answers
25 views

Create Chrome Storage Sync Get Array [on hold]

Currently I have a working function that individually goes through, obtains the set synced data in Chrome and then sets the value of a corresponding ID element with the returned value of the get ...
1
vote
0answers
25 views

Beginning of any maximum ascending slice of an array A of maximum size

I want to write a function public int solution(int[] A) that, given a zero indexed array A consisting of ...
0
votes
0answers
44 views

Serialize data into one byte array using ByteBuffer

I have a class in which I am passing certain parameters through the constructor and then using those parameters to make one final byte array with a proper format (header + data): ...
2
votes
1answer
118 views

Count the number of times a particular number appears in a sorted array of integers

I had an interview question awhile back that went more or less as follows: You have a sorted array of integers representing the ages of every person living on earth. There's a single entry in the ...
-1
votes
0answers
25 views

Libgdx/Java - How to find the distance between multiple objects in an array [closed]

So I'm currently working on a game where multiple meteors spawn and you have to avoid them. The problem is the meteors sometimes spawn overlapping each other, which I don't want. I want them to spawn ...
2
votes
0answers
63 views

Storing and accessing 3D struct array efficiently

I have a structure, and have come up with 3 different 3D arrays to store it in. The thing is, optimization is not my specialty and I need advice from someone who knows their stuff regarding best ways ...
4
votes
4answers
295 views

Find element that has been removed from a shuffled array

For a function to determine which element has been removed from a shuffled array, I came up with: ...
-3
votes
0answers
18 views

Modify the given sequence such that after several operations all elements are zero [closed]

The is the given problem on HackerEarth: Suppose we have a sequence of non-negative integers, Namely a_1, a_2, ... ,a_n. At each time we can choose one term a_i with 0 < i < n and we subtract 1 ...
3
votes
1answer
38 views

Practicing Arrays with String Class methods

I am a Spanish programming teacher in a vocational training course. We are studying the arrays and in order to practice and to get the students familiarized with some methods of the String class, I ...
0
votes
1answer
31 views

Get sum of an array in 3 ways, for, while and recursive

So i was trying to find sum of an array using 3 ways in perl6 for while recursive (I know there are inbuilt perl6 functions for this) I want to know if there is a better way to do this or is this ...
0
votes
3answers
90 views

Find the smallest 3 numbers from a total of 5000 numbers

Today was my interview. The question which was asked was: Give an efficient solution to search smallest 3 numbers from a given array. The array contains unsorted numbers which can also ...
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, ...
2
votes
2answers
44 views

Compare two arrays and show number of matches in a percentage value

I wrote this to be able to compare two different arrays to figure out how many words were in common as a percentage value. The use case is that I have array a which is a list of the most commonly ...
3
votes
1answer
82 views

Converting Integer to dynamically allocated Char array, digit by digit using pointers

Problem: Write a function to convert Integer to String, using only pointers, without array indexes, string must be dynamically allocated. ...
4
votes
2answers
133 views

Generate String Combinations

I have created an algorithm that can generate all possible combinations of a string given its length, and character set (it uses a custom numeral system to do this). How could I improve its ...
0
votes
2answers
68 views

Iterating through specific elements of an array with filter()

I have the following code which iterates through some divs of an array to show() them. I was wondering if there is any way to rewrite the ...
12
votes
4answers
935 views

Leetcode 15. 3 Sum

Problem statement Given an array S of n integers, are there elements a, ...
3
votes
0answers
46 views

Substitute for `std::array::operator[]` in C++11 by using template-based recursion

What follows is a simplified version of a tentative implementation for a template-based set, named TemplateArgs. For the sake of clarity and focus on the question ...
5
votes
3answers
131 views

Tree abstraction

This code provides a Tree abstraction. I would like to finalize the code structure only in tree directory, before starting ...
4
votes
1answer
47 views

Lexicographically smallest wave like array without sorting

Given an array of integers, sort the array into a wave like array and return it. In other words, arrange the elements into a sequence such that a1 >= a2 <= a3 >= a4 <= a5..... Example: Given [...
4
votes
3answers
461 views
1
vote
2answers
102 views

HackerRank, Cracking the Coding Interview: Arrays - Left Rotation

I just wanted to get some constructive feedback on my solution for this problem taken from the HackerRank Cracking the Coding Interview series. CTCI Arrays Left Rotation Problem Statement ...
11
votes
5answers
936 views

Zero-initializing large dynamically allocated arrays of double

Arrays of double can be zero-initialized with the { 0 } initializer, which works even on systems that have a binary ...
7
votes
2answers
56 views

C function to print arrays of arbitrary data type

C is naturally clumsy at polymorphism but I wanted to avoid duplication so I wrote this function. But I'm sure there are ways left to improve it. Please not that for brevity's sake not all data types ...
1
vote
2answers
55 views

Addition of two number using array of unequal size

I tried my level best to get it done. But I would like to have a better solution in all terms. Given 2 huge numbers as seperate digits, store them in array and process them and calculate the sum ...
6
votes
2answers
614 views

Algorithms to find statistical information of an array

I was working on a program that creates an array, then gives statistical information about that array such as std dev, median, mode average etc. I have written a method for each statistical value, ...
5
votes
6answers
917 views

Python code to check if an array has a sequence (1,3,4)

I recently applied for a job as a Python coder but was rejected. This was the problem: Write a python code to check if an array has a sequence (1,3,4) Assuming they were looking for expert Python ...
3
votes
3answers
49 views

Push an item onto the end of array in Java

I want to make a method arrayIntPush(3, {5,4,8}) that will return {5,4,8,3}. This method seems to work: ...
1
vote
1answer
40 views

Add 1 to a number represented as an array of digits, using recursion

Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most significant digit is at the head of the list. Explanation for using ...
3
votes
1answer
27 views

2D matrix - splitting the matrix in two parts with equal number of elements

The elements in the matrix are either 'M', 'G', 'P' or '.' and the algorith must write out all possible ways of splitting the matrix so it has equal number of M, G and P on each side. It's a task we'...
0
votes
1answer
43 views
1
vote
3answers
49 views

Resize the hash table and rehash every element

I'm trying to increase my hash table size by two if the table is filled more than half of it. I tried to rehash every single element from the old table and put it back to my new table, then assign my ...
3
votes
3answers
210 views

Using Dynamic to create and then flatten an arbitrarily-nested array

I have some code that I posted as a possible answer on StackOverflow (and the code I post here is almost an exact duplicate of that, but I'd rather include complete information in this post as well so ...
0
votes
2answers
57 views

Nested file_get_contents / json_decode

I have this code but it takes over a minute to run. I'm looking at around 400 entries being brought back for the first loop. Any ideas on how it could be improved for speed? ...
11
votes
3answers
2k views

Battleship console game

This is a battleship console game I wrote in C++. ...
0
votes
1answer
54 views

Finding the array indices of three specific headers

I'm considering how to refactor code to make it clean & clear. There are some principles to make code clean; in this case I think it's Single Responsibility and One level of abstraction. The ...
0
votes
0answers
41 views

Assignment of Array to Property in class constructor

I'm writing classes to decode and persist Message's sent via TCP. Each message contains many DataField's. I have a simple class DataField class that holds some ...
0
votes
1answer
93 views

Splitting Excel workbook sheets

Running Office 2007, I have master workbook with data, which I: Split master sheet data to new sheets for every salesmen Create new workbook (with 1 sheet) Put sheets of salesmen to an array ...
3
votes
2answers
45 views

Strictly Identical arrays input

The textbook problem: (strictly identical arrays) Two arrays list1[] and list2[] are strictly identical if they have the ...
8
votes
3answers
159 views

Magic square test

A magic square adds up the values in each vertical, horizontal, and diagonal row to the same value. In this case, that value is 34. I have changed different indices values and the program returns <...
2
votes
3answers
95 views

Fast find exist in list or not

I want to determine whether or not the selected element exists in the list. This is the current procedure that I'm using for finding the element exist in a list or array. Is there any fast procedure ...
5
votes
3answers
871 views

Finding the minimum number of moves to achieve equal array elements

Long story short, the other day I discovered the site LeetCode and started solving some of its problems until I stumbled onto this one. I'll paste the description here: Given a non-empty integer ...
6
votes
1answer
51 views

Counting sort implementation in C

I've just implemented counting sort in C and would like to hear your opinions on it. As I'm usually being rather picky when rating other people's code, please go ahead and be picky, too -- I will try ...
5
votes
1answer
88 views

Isomorphic strings in LeetCode

I solved this problem: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrences of a ...
2
votes
1answer
62 views

Splitting an array into stride by 2

i've written a basic function to split an array into stride by 2: ...
6
votes
1answer
217 views

Connect Four in Java

I wrote this program as an assignment for an introductory programming course in Java, which I then decided to improve past the minimum assignment requirements. It allows two human players to play ...
0
votes
0answers
41 views

Find max in-order difference in array

Given an array A of integers, find the maximum of j - i subjected to the constraint of A[i] <= A[j]. If there is no solution possible, return 0. Example : A : [3 5 4 2] Output : 2 for the pair ...