# Questions tagged [array]

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.

1,602 questions
Filter by
Sorted by
Tagged with
141 views

### Counting contiguous subarrays with a negative sum

I'm doing a coding challenge that asks to count the number of contiguous subarrays that have a negative sum: A subarray of an n-element array is an array composed from a contiguous block of the ...
41 views

### Generating random N-dimensional arrays

For this code challenge, I want to create a performant function that creates a rectangular N-dimensional array. (min_dim_size, max_dim_size) is the span size of every dimension. So ...
35 views

### Algorithm that parses through input of points and finds distance

I'm wondering if someone could take some time to review this script. I'm parsing through a list of points of any length and calculating the distance. I'm wondering how to make my code better/more ...
523 views

### Summed absolute difference of two array

Question (SAD Queries on CodeChef) The Summed Absolute Difference (SAD) of two arrays. Given arrays (1-indexed) $P$ and $Q$ of lengths $p$ and $q$. Given a collection of $n$ arrays ...
90 views

### Possible letter combinations of a dial pad in linear time using a recursive approach

Time complexity: I walk the initial unzipped array of keys representing the number O(N) backwards. I then do an inner walk of the proceeding array of letters *O(L^2), mapping it to every value in the ...
164 views

### Find value that occurs in odd number of elements

I am trying to solve the following exercise using Javascript: A non-empty array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be ...
177 views

### Add item at the beginning of each inner array in jagged array

So, there is a big jagged string array (~ [120] [1 000 000]) here that represents data from an excel worksheet ( columns / rows). Task: We have to append items at the beginning of each inner array. ...
148 views

### Primitive ArrayList Implementation

I have implemented a primitive ArrayList class in C++ as part of an attempt to learn about data structures and their optimizations. It currently has: Constructor/...
5k views

### Hacker rank 30 days of code Maximum Sum of Hourglass

I came up with this code as a solution to a contest question. The original question can be viewed here for attribution sake: Hackerrank 2d array problem Sample input is like this: ...
433 views

### JavaScript Determine if Array has Almost Increasing Sequence

A coding challenge on a website says to determine if an array would have an increasing sequence if one element were removed from that array. Here is the function: ...
1k views

### Removing leading new line from byte[]

Given this piece of code, what is a better way to write it (cleaner). It is taken for granted that data will not be null, nor its length will be 0, so this check is ...
401 views

### Determine if Array has an Increasing Sequence

I wrote a function in JavaScript that expects an array of integers (negative or positive) and determines if that array has an increasing sequence. For the sake of better time performance I made the ...
7k views

### Checking whether an array contains a value or another array

I'm designing an isIn method that takes a value:any and checks whether it exists in an array. It's working, but I'm wondering ...
177 views

### Make an Array Reactive (Observable)

I have written a simple JavaScript function to make an array reactive (i.e. observable). Is there anything I could improve? What the code does is take an array, a callback and a ...
58 views

### General use multi-dimensional container using operator[]

This is a followup to a previous question of mine on same subject. Context I want to have a tool that allows to simulate as much as possible a C++ standard container for a multidimensional ...
119 views

### Calculate min, max, mean and median out of array Version 2

This question is a follow up of: Calculate min, max, mean and median out of array I took all the suggestions an reworked the code. Like the description of the excercise suggests i only use one ...
90 views

### PHP function to extract numbers from the list whose squares are exceed some threshold

This is my naive approach: ...
2k views

### Calculate min, max, mean and median out of array

Another C exercise: Write a function that takes an array of 'ints' as its input and finds the smallest and largest elements. It should also compute the median and mean. Use a ...
579 views

### Finding Repeat and missing numbers in an array

Problem Statement: You are given a read-only array of n integers from 1 to n. Each integer appears exactly once except A which appears twice and B which is missing. Return A and B. ...
125 views

### Finding the smartest set from an array of numbers

Is there any way to make this program run in better time ? While running, it is taking 1 second for the sample test case to pass and 5-10 seconds for the rest of the test cases. Problem statement ...
61 views

### Count the number of ways to make a given sum using one number from each array

I have three arrays, each of which contains only numbers. Given a target number, I need to return the number of ways I can make that sum, using exactly one number from each of the arrays. For example:...
81 views

### Find select values on one worksheet and copy to a second

In the Calculator worksheet of my spreadsheet, for any appliance type present in a building being studied, users enter a quantity. There are 18 different appliance ...
92 views

### Algorithm for tagging list of substrings from a list of strings

I have a list of utterances(strings)/corpus as the follows, ...
24k views

### Determine whether to push or update object in array based on unique ID

I am trying to write a basic function that will decide whether the object already exists in array of objects based on unique id that is inside this object as a property. Upon searching I came up with ...
233 views

### Multi-dimensional container using operator[]

This is a late followup to a previous question of mine on same subject. Context: I want to have a tool that allows to use all the C++ goodies (algorithms, for loop on containers, etc.) on a ...
908 views

### Shuffling an array keeping some elements fixed

The task is simple to understand: how to shuffle an array keeping some elements fixed. Let us take an example: starting from the array [1, 2, 'A', 3, 'B']. Having ...
148 views

### Writing Merge Sort in C++

I am learning programming online and currently watching CS50 lectures, in third lecture, professor introduces us to merge_sort though only through pseudo code, so I wanted someone to review my ...
78 views

### C++ std::array reimplementation [closed]

As a conceptual implementation of the default c++ std array interface, would this be a suitable implementation & what is the safety of this implementation? ...
381 views

### Wrapper for a raw array so that it can be passed to templates expecting Standard Library containers

I am working with a code base where unfortunately I cannot replace all raw arrays with std::array. The spec provides no guarantee that the memory layout of a ...
5k views

### Encrypt a byte array

This code is a Frankenstein. I found ten examples done in ten different ways and my requirements were slightly different so even if they were reliable they weren't a copy and paste solution. Encrypt ...
153 views

Preliminaries I have optical sensor ADNS2610 (see datasheet here). There are a few problems which it can be used to solve, but for now let us focus on getting an image from that sensor. This sensor ...
654 views

### print array of previous smaller elements

I am solving interview question from here. Problem : Given an array, find the nearest smaller element G[i] for every element A[i] in the array such that the element has an index smaller than i. ...
397 views

### “Ease the Array” challenge

I'm working on this challenge: Given an array of integers of size N. Assume ‘0’ as invalid number and all other as valid number. Write a program that modifies the array in such a way that if next ...
428 views

### Shift one value of array values to the beginning

Given an integer \$value in the range of 1, 2, 3, I want to get an array that starts with ...
5k views

### Finding the largest value in a 2D array

I'm pretty new to Java and programming in general and I'm doing practice problems from my textbook over the summer to try to get ahead. This is a simple program that finds the largest value in a 2D ...
54 views

### Generate 2D array with set amount entries

I want to generate an array where each row and column needs to have a random generated amount (between 2 and total size of dimension -1) of true values. Currently I am running each row then columns ...
2k views

### Generic Array (Vector) Class C++

I am a mathematician trying to learn how to become a better programmer in C++. I am currently now trying to write the main data structures from scratch. I have now completed a generic array class and ...
178 views

### Retrieve words from dictionary when they meet letter requirements

I have a set of functions that retrieve words from some arbitrary dictionary based on what letters they have. For example, this function gets words that use only the specified letters: ...
3k views

### Find maximum gap between elements of an array

I am solving interview questions from here. Problem : Given an array A of integers, find the maximum of j - i subjected to the constraint of A[i] <= A[j]. Example : A = [3 5 4 2] Output :...
694 views

### High performance primitive dynamic array

Unfortunately Java does not support generic programming with primitive types. Using collections classes with boxed types may increase memory usage by a factor of 3-4 (e.g. ...
150 views

### Check whether array is sorted recursively

I'm trying to implement isSorted method checking whether given array is sorted recursively. I've written two types, one is similar to merge sort logic, the another ...
243 views

### Sort array into wave like array

I am solving interview questions from here. Problem : 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 ...
53 views

### Duplicating an array

This code returns an array that consists of two copies of the input array. Can you review this algorithm? ...
65 views

### Find a number which equals to the total number of integers greater than itself in an array

I am solving interview questions from here. Problem : Given an integer array, find if an integer p exists in the array such that the number of integers greater than p in the array equals to p. ...
317 views

### Find the missing number and repeated number

I am practising interview questions from here. Problem : You are given a read only array of n integers from 1 to n. Each integer appears exactly once except A which appears twice and B which is ...
915 views

### Sum of absolute difference of values and corresponding indices of an array

I am solving questions on arrays from here. Problem: You are given an array of N integers, A1, A2 ,…, AN. Return maximum value of: f(i, j) for all 1 ≤ i, j ≤ N. f(i, j) is defined as |A[i]...
94 views

### Fold large input lines into smaller ones

I am working on a program that is meant to fold a large input line into smaller ones. Basic flow of the program would be as follows: User calls the program with a long string as input Program prints ...
95 views

### Swapping int with string using getchar() and putchar()

I wrote code that replaces integers from 0 to 3 with strings. I was only allowed to use getchar() and putchar(). If the input is ...