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

3
votes
1answer
32 views

Find the lowest and second lowest values in an array of numbers

Trying to find way to do this with only one pass through the array, so I won't run a sort on it and take arr[0..1]. Not sure how to make it look better: ...
0
votes
0answers
32 views

Java Random number generator Excluding values in an array [on hold]

My problem is that I have a random number generator method in which I would want to generate random numbers excluding numbers stored in an array/ArrayList. For ...
3
votes
3answers
105 views

Copy part of array in javascript

I have an array and must fill another one. Depending of a boolean I copy first or second element and the rest must be as is... Currently I do it like this (data ...
0
votes
0answers
13 views

ArrayList Lab Error in the Output / Incorrect Outout [on hold]

The output of this code should be the arraylist words and the toString that you will see below, but it is just “file.txt” in the form of a String. I really can't understand why this is happening could ...
5
votes
3answers
111 views

Check if two strings are permutations of one another

I am working my way through "Cracking the coding interview" problems and have finished implementing this question: "Given, two strings, write a method to decide if one is a permutation of the other". ...
4
votes
3answers
58 views

Setting the page number with a default

Consider this code segment: if (empty($_GET)) { $page_number = 1; } else { $page_number = $_GET["page_number"]; } I wonder if there is a better, more ...
4
votes
3answers
113 views

Simple array usage demonstration

I just finished this code for my own practice purpose. This code works just fine but I understand there still a lot insidious problems. Any advice for improvement would be appreciated. So here it ...
3
votes
2answers
36 views

Non-re-indexing List with defragmentation

I'm currently coding something where I have Objects that take on an ID, and are stored in a List. For easy retrieval, the ID of the object is it's index in the list. However, that means that the ...
3
votes
1answer
128 views

Generate random and unique array of int values for a given size

I need to generate an array of int values for a given size, the values should be random and unique. the following implementation is "ok" for small values [1,10k], I ...
0
votes
0answers
24 views

KnapSack Solution using recursion and Arrays [closed]

I would like to know the best possible way to modify this code. Instead of adding the integers to an array in the code itself, I would like the user to input the different weights and the capacity via ...
3
votes
1answer
56 views

Remove Duplicates from Array in Swift 3.0

I ran the following code through a Leetcode.com challenge and it says the runtime for the test cases is 119ms, which puts it at the back of the pack performance wise. The goal is to remove duplicates ...
3
votes
1answer
31 views

SmallArraySlide constructor

I'm learning to do some small programs in JavaScript and I did some sort of arraySlider (I don't really know how to call it). I would like to have some feedback to ...
3
votes
0answers
32 views

With 2 sets of strings, find a string that can be constructed from either set

Given the following sets of strings: are yo you u how nhoware alan arala dear de I need to find a sequence that can be constructed by concatenating the strings ...
1
vote
0answers
28 views

Draw directional flow on html5 canvas grid/checkboard with respect to user defined size and limits

Ultimately I want to be able to draw a checkerboard (wall) of user-defined size. This wall is made up of tiles of a user-defined size. This main wall can then be split up into multiple sections (...
5
votes
2answers
59 views

FixedArray Class In Ruby

I had an assignment recently to build a FixedArray using Ruby. It's supposed to simulate a FixedArray in C, that is, an array ...
0
votes
1answer
56 views

Converting a 2D array to a JSON list

I am wondering if I could implement this in a cleaner, more elegant, strictly functional way: ...
2
votes
0answers
40 views

Spellchecker program is having issues due to vowel checking method

This program takes in a list of 275k or so words from '/usr/share/dict/words' and loads them into HashSet. It then takes in a list of 1000 words (taken from the dictionary and are scrambled (vowel ...
8
votes
6answers
838 views

Reversing an array in Python

Reversing an array in Python without using a built-in function: ...
2
votes
0answers
58 views

Find the minimum value in a circular list of integers

I was looking up some coding challenges and this looked like a fun one to solve. I tested it with the following values and it seems to work for those at least: [ 5, 7, 8, 9, 11, 2, 3 ] [ 5, 7, 1, 4] [...
5
votes
0answers
46 views

Checking game objects versus each other to determine targets, comparing arrays

I have a flight class that looks like this: ...
1
vote
1answer
96 views

Codewars “Consecutive strings” kata

The challenge description is as follows: You are given an array strarr of strings and an integer k. Your task is to return ...
1
vote
0answers
38 views

a way to rewrite compress and ensure capacity methods in an array

I've been working on this array, and I was wondering if there was any other way to rewrite the compress and ensure capacity methods since I've been running into problems with a different application ...
4
votes
0answers
72 views

Find kth largest element in the union of two sorted array (Follow up)

Problem statement: Find \$kth\$ largest element in the union of two sorted array, assuming that two sorted arrays are in ascending order. The size of two arrays are \$m\$, \$n\$. My introduction of ...
5
votes
4answers
249 views

Find a list of objects in an array with JavaScript

Having an array of objects, such as numbers, what would be the most optimal (Memory and CPU efficiency) way if finding a sub group of objects? As an example: ...
3
votes
2answers
69 views

Find most occurred number in sorted array of numbers

I was asked in an interview to find the a number in an sorted array of numbers which has occurred maximum number of times. Also find the count of occurrence of that number. I solved it in javascript,...
3
votes
2answers
67 views

Order line reversing (reversing line order)

I'm a student learning to code in C. I had to make a program for class to reverse lines of input from the keyboard (not character wise, but reverse the order of the lines input). The program is ...
3
votes
2answers
99 views

One-dimensional circular Conway's Game of Life

I have a program that is working, but it takes way too long to get the answer. With input like 15 100000000 111010111001100 The program checks for 15 numbers, ...
3
votes
1answer
36 views

Iterating over an object that contains arrays

I have an object that has an array inside with another object inside. I iterate over the object and array to print out the first name and last name of the people inside the array of objects. I am ...
1
vote
1answer
122 views

Tic Tac Toe game in Java vs computer

I am trying to create a Tic Tac Toe game in Java using a 2 dimensional array. The computer has to do the smartest move. ...
1
vote
2answers
103 views

Sum Of Two Arrays element by element and arrays can be of unequal length

In this question, I need to find the sum of 2 arrays element by element. Arrays can be of unequal length. Explanation: Sum of [1, 0, 2, 9] and [3, 4, 5, 6, 7] is [3, 5, 5, 9, 6] and the first digit ...
1
vote
1answer
63 views

My implementation of dynamic array

Below is my implementation of dynamic array without help of library functions. Kindly provide your suggestions on design, coding style and algorithm. MyDynamicArray.java ...
0
votes
1answer
50 views

Serialize all the fields into one byte array and deserialize byte array into individual fields

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) and it works fine: <...
5
votes
1answer
55 views

Finding all neighbours of a node sliding tile

So I have some code which finds neighbours of a given State. So the positions the blank tile (which is represented as 0 in my code) can be moved. I am doing the 3x3 tile puzzle. The goal state is ...
1
vote
2answers
116 views

Setting icons when a tab is selected

I have this 2 arrays : ...
2
votes
1answer
54 views

Display four random entries from an array

This code will take the array shown and display 4 random entries in the format shown (or near enough). Any part of this that can be optimised? I'm not happy about the ...
1
vote
1answer
49 views

PHP handle array when query database with one-to-many relationship

Well, I am writing a web service using PHP to return data from a DB in JSON format. I need to query 3 tables, which have a one-to-many relationship, like shown below: ...
8
votes
2answers
88 views

Short and Messy Polybius Square

I attempted to recreate the Polybius square, also called the Polybius checkerboard, which was used in Ancient Greece for cryptography. Since it is an uncommon cipher, it is nowhere on Code Review. ...
5
votes
2answers
69 views

Checking whether the max and min values occur equally frequently

An array is defined to be "maxmin equal" if it contains at least two different elements and the number of times the maximum value occur is the same as the number of times the minimum value occur. So {...
1
vote
3answers
41 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 ...
-1
votes
1answer
56 views

Initializing a big static array for a card-based iOS app

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 ...
2
votes
1answer
53 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
47 views

Create Chrome Storage Sync Get Array [closed]

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
1answer
145 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
137 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 ...
2
votes
1answer
77 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
448 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
1answer
44 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 ...
1
vote
1answer
37 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
95 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 ...