# Questions tagged [array-manipulation]

A competition to solve a particular problem through the usage and manipulation of arrays.

171 questions
Filter by
Sorted by
Tagged with
3k views

### Remove surrounding zeroes of a 2d array

This is a 2-dimensional version of this question. Given a non-empty 2-dimensional array/matrix containing only non-negative integers:  \begin{bmatrix} {\color{Red}0} & {\color{Red}0} & {\...
1k views

### An Array of Challenges #2: Separate a Nested Array

Note: This is #2 in a series of array-manipulation challenges. For the previous challenge, click here. Separating Nested Lists To separate values in a nested list, flatten it, and then wrap each ...
4k views

### Reverse Array Sum

Your program should take an array as input. The array: Will always be 1 dimensional Will only contain integers Can be empty The program should reverse the array, and then add up the elements to ...
3k views

My first code golf post, apologies for any mistakes... Context In rock climbing (bouldering specifically), the V/Vermin (USA) climbing grades start at 'VB' (the easiest grade), and then go 'V0', 'V0+...
4k views

Definition An arrowhead matrix is a matrix that has all entries equal to 0, except the ones on the main diagonal, top row and leftmost column. In other words, the matrix should look like this: * * * ...
1k views

### Rotating a 2D Matrix

Let's say I have the following (2D) matrix: [[1, 2, 3, 4 ], [5, 6, 7, 8 ], [9, 10, 11, 12], [13, 14, 15, 16]] Rotate the matrix counterclockwise ...
3k views

### Triangle a number!

We are used to the term "squaring" n to mean calculating n2. We are also used to the term "cubing" n to mean n3. That being said, why couldn't we also triangle a number? How to triangle a number? ...
1k views

### Raise a single number

Introduction Suppose you want to compute the tail maxima of a list of numbers, that is, the maximum of each nonempty suffix. One way to do it is to repeatedly choose one number and replace it by a ...
7k views

### Find the longest word in an array

Your challenge is to take an array of strings and output the longest string in the array. So for ["tiny", "small", "bigger", "biggest"] the output would be ...
2k views

### Reverse positive runs

Input Your input is a list of single-digit numbers in any reasonable format, including a string of digits. The input will not be empty. Output Your output shall be the input list, but with each ...
1k views

### Book Stack Sort

When stacking books you usually want to put the largest ones at the bottom and the smallest ones at the top. However, my latent OCD makes me feel very uneasy if I've got two books where one is shorter ...
431 views

### One goes up, the other comes down

Introduction In this challenge, your task is to decide whether a given sequence of numbers can be separated into two subsequences, one of which is increasing, and the other decreasing. As an example, ...
1k views

### Are the lists divisible?

Inspired (with the explanation stolen from) this Background Say you have two lists A = [a_1, a_2, ..., a_n] and ...
1k views

### Extract Local Maxima

Given an array of positive integers, output an array of all the elements that are greater than or equal to the adjacent ones. Most elements will have two adjacent elements; the first and last element ...
2k views

### An Array of Challenges #3: Moving Averages

Note: This is #3 in a series of array-manipulation challenges. For the previous challenge, click here. Moving Average of a List The moving average of a list is a calculation resulting in a new, ...
2k views

### Output a string's cumulative slope

Challenge Given a string such as Hello World!, break it down into its character values: ...
767 views

### Stable positive/negative separation [closed]

From SO. You are given an array with positive and negative integers. Write a function to change the elements order in the array such that negative integers are at the beginning, the positive integers ...
4k views

### There are two new sheriffs in town – Identifying DJMcMego pairs!

We have some new sheriffs moderators in town, Mego and DJMcMayhem. We need a challenge to properly honour them for their new positions, so there we go. Here's something that has caught my attention ...
5k views

### Covering a Skyline with brush strokes

Given a non-negative integer skyline height list, answer how many uninterrupted 1-unit-high horizontal brush strokes are needed to cover it. [1,3,2,1,2,1,5,3,3,4,2]...
1k views

### B​u​i​l​d a n​e​s​t

The challenge is simple: write a program or function that, when given a finite non-negative integer, outputs a nested array. The rules Your code must produce a unique valid nested array for every ...
911 views

### Does the sum of 2 numbers in the list equal the desired sum? [duplicate]

The Task This is my first challenge so apologies if it is very simple! In this challenge, your task is to write a program or function which takes in a list of integers and a desired sum and outputs ...
1k views

### Parity of sum of other elements

Task Given an array of positive integers, replace each element with the parity of the sum of the other elements. The array is guaranteed to have at least 2 elements. Definition Parity: whether a ...
1k views

### Leaving the Nest

Given a non-flat list of integers, output a list of lists containing the integers in each nesting level, starting with the least-nested level, with the values in their original order in the input list ...
2k views

### Find a maximal rectangle of 1s

Background I want to buy an plot of land and build my house on it. My house should be rectangular, and as large as possible; however, the available plots have lots of rocky areas that I cannot build ...
3k views

### Matchmaker, Matchmaker, make me a match

(we won't be finding a Find or catching a tryCatch, though) This is part two of a multi-part series of implementing some ...
2k views

### Repeat this GCD operation

Problem A3 from the 2008 Putnam competition says: Start with a finite sequence $a_1, a_2, \dots, a_n$ of positive integers. If possible, choose two indices $j < k$ such that $a_j$ does not ...
3k views

### Does it oscillate periodically?

Challenge Given a list, determine if grouping the list into runs of increasing and decreasing elements will result in a list of equal-sized lists. In other words, "turning points" of the list are ...
645 views

### Rubik-sorting a matrix (a.k.a. the torus puzzle)

The idea for this code-challenge is simple: given a matrix of integers, let's sort it by applying Rubik-style movements. This means that you can select a single row or column and rotate its elements ...
3k views

### Get the closest value to number

In this code golf, you need to get the closest number from another one in a list. The output may be the closest number to the input. Example: ...
2k views

### Get the indices of an array after sorting

Your challenge today is to write a program or function which takes a list l and gives the positions in l at which each ...
990 views

### Fivenum and a little bit

(a paradox, a paradox, a most ingenious paradox) This is the first part of a multipart series inspired by different R functions. The Task Given a dataset $D$ of positive integers, I need you to ...
842 views

### Un-Merge a List

Introduction Most of you are familiar with the merge sort algorithm for sorting a list of numbers. As part of the algorithm, one writes a helper function called ...
627 views

### Inverting lists of lists of indices

Inspired by this StackOverflow post. Introduction Bob's job is to create spreadsheets and organize them. The way he organizes them is known to very few except for Bob, but he creates a list of each ...
690 views

### Grouping Array Data

Given an integer matrix a and a nonnegative integer i, output a mapping b that maps the ...
2k views

### Trim that distracting background off!

Isn't it annoying when you're taking a picture, but the background detracts from the actual substance of the image? I'd say it is. I need to know how much I should crop so that I get rid of this ...
498 views

### Count the contiguous submatrices

Migrated from chat Given two non-empty non-negative integer matrices A and B, answer the number of times A occurs as a contiguous, possibly overlapping, submatrix in B. Examples/Rules 0. There may ...
2k views

### Find the “unwrapped size” of a list

Let's define the "unwrapped size" function u of a nested list l (containing only lists) by the following rules: If ...
926 views

### N-chotomize a list

Given a list of integers L, and an integer N, output L splitted in ...
645 views

### Sort and Re-apply Deltas of an Array

It seems that any Simple Modification of deltas using a consistent function can almost always be done some other shorter way, Dennis. Thus, the only solution I can imagine to make this harder, is to ...
1k views

### A classic sorting code-golf question

This is a code-golf question. Input A list of non-negative integers in whatever format is the most convenient. Output The same list in sorted order in whatever format is the most convenient. ...
668 views

### Shortest program to split special array

Background Imagine, you have a big array A, which is mostly zeroes, but contains a short subarray B which has only strictly ...
437 views

### Hilbertize an image

For a computer vision app I want to do a mapping of an image, in such a way that every pixel fit hilbert curve, instead of conventional layout. So task could be as follows: Task description Given ...
548 views

### Polynomial extrapolation

Task Given a list of integers a1, a2, …, ak (k ≥ 2) and a positive integer m, write a function or a complete program that calculates the next m numbers of the list. Assume that ai = P(i) ...
659 views

### Dancing arrays. Output them with some forward-backward moves

The task is to create a program (or a function), which outputs array elements in the order, determined by two numbers F and B. F is number of elements to print, B is the rollback distance (from last ...
307 views

### John's lost arrays

John has made an array of numbers which are important to him. Unfortunately, John lost the array. Luckily, he knows some details about the array. You will receive each of these sets of details (...
2k views

### Reverse a 1-dimensional array

Note: This challenge is not the same. Challenge Believe it or not, we haven't got ONE challenge for reversing one-dimensional arrays (although we've got one for n-dimensional ones)! This should ...
2k views

### Illustrate the square of a binomial

Given (by any means) two different natural numbers (of any reasonable size), output (by any means) the square of their sum as in the examples below: Given 4 and 3, output: ...
5k views

### Separate a list into even-indexed and odd-indexed parts

Inspired by this question: Make a function (or a full program) that receives a list of numbers and outputs the list rearranged, so that even-indexed numbers appear first, and odd-indexed numbers ...