# Questions tagged [array]

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

799 questions
Filter by
Sorted by
Tagged with
1k views

### Just another traffic jam!

One lane is closed, the vehicles have to thread their way in according to the zip-lock system: One car from one lane, the next car from the other lane, always taking turns. Input: Two vehicle queues, ...
• 1,600
3k views

### Which skill to train?

Story (skip, if you prefer the naked task): You need five skills for an imaginary sport: Speed, strength, endurance, accuracy and tactics. If you achieve a score in each of these disciplines, you can ...
• 1,600
303 views

### How many twisted corners?

Your challenge is to output the number of twisted corners given a 2x2 Rubik's Cube scramble. For the purpose of this challenge, twisted corners are defined as corners where the colour of the top/...
• 8,463
2k views

### Seat gangs as far as possible

Imagine there are $n$ people $\{a_1, a_2, \ldots, a_n\}$ who enter a room in order and sit down in $n$ seats, arranged in a row. Each of these people belong to some gang, indicated by an integer ...
• 7,061
4k views

### How many umbrellas to cover the beach?

You work at a beach. In the afternoon, the sun gets quite hot and beachgoers want to be shaded. So you put out umbrellas. When you put out umbrellas you want to shade the entire beach, with as few ...
• 96.5k
1k views

### Transpose a multidimensional array

Transposition is an operation on 2-dimensional arrays that flips every element across the main diagonal: ...
• 35.6k
796 views

### Output the longest list

In this challenge you will take a non-empty (finite) list of (possibly infinite) lists of positive integers, and your task is to output the longest one. An infinite list is longer than a finite list ...
• 96.5k
2k views

### Complement an infinite list

In this challenge, we define the complement of a list of positive integers as all positive integers not included in that list. For example, the complement of the even numbers ...
• 35.6k
1 vote
544 views

• 8,538
650 views

### Complete the landscape

Carcassonne is a tile-based game, where the objective is to construct Roads, Cities and Monasteries, in order to score points. The game works by players taking turns to draw and place tiles to ...
• 49.4k
1k views

Given a list, L, of sets of numbers like this: [[1], [0,2,3], [3,1], [1,2,3]] Output a single list of numbers such that 2 ...
• 11.8k
2k views

### Compute cumulative means efficiently

Consider a sorted array of positive floating point numbers such as: input = [0.22, 2.88, 6.35, 7.17, 9.15] For each integer $i$ from 1 up to the last value in ...
• 1,812
896 views

### "Signpost" puzzle from Tatham's collection

Simplified version of "Signpost" puzzle from Simon Tatham's Portable Puzzle Collection. How the puzzle is created We pick up randomly positive integer N ...
• 3,239
1k views

Background Being in a philosophical mood, I remembered one old idea. I think it is suitable for CG. Duplicates are not found, but it's of course just a kind of totalistic cellular automaton or erosion....
• 3,239
2k views

### The Jaccard Index

The Jaccard index / similarity coefficient, also known as the Tanimoto index / coefficient, is a statistic used for gauging the similarity and diversity of finite sample sets. It was developed by ...
• 1,597
2k views

• 3,650
605 views

### Find the largest sum of any contiguous subarray of the array [duplicate]

Let's say you are given an integer array. Create a function to determine the largest sum of any array's adjacent subarrays. For instance, the contiguous subarray with the largest sum is ...
2k views

### Arbitrary Apple Dilemma

I have encountered this type of puzzle, that usually involves apples, several times. It goes as follows: There is a certain number of apples in a basket. Ava takes a third of the apples. Bob takes a ...
• 8,463
1k views

### Change the subject

Sometimes I feel like the conversation is going down the wrong path and take it upon myself to steer it in another direction. And this conversation is going wrong real fast, so I need to change the ...
• 5,212
730 views

### Form a subset that is a continuous range

Given a list of lists of positive integers, output a subset of them so their union forms a continuous non-empty range with no numbers missing. For example, consider this input: ...
• 11.8k
2k views

### Remove duplicates from my academic transcript

Consider a list of subject, grade pairs. E.g. ...
• 1,812
1k views

### Keep elements in sequence that have a letter repeated at least 3 times

Challenge: Given the input array l with a list of strings, only keep the elements in the sequence that have a letter that's repeated at least 3 times. Like ...
• 2,001
735 views

### Create $n$ sublists with the powers of two (1, 2, 4, 8, 16...)

Challenge: Given the input number n. It should give me nested sublists of n layers with the power of two numbers for each level. ...
• 2,001
865 views

### Generate recursive "arrays" up to a certain depth

Given a positive integer n. Generate a JSON array (can be a string, or your language's built-in JSON representation as long as we can get valid JSON, (your code ...
• 183
659 views

### CGAC2022 Day 8: Fen The Wicked, Part 2

Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details. Fen is a magician Elf. He can cast spells on an array of numbers to produce another number or array of numbers. One ...
• 73.8k
1k views

### CGAC2022 Day 7: Fen The Wicked

Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details. Fen is a magician Elf. He can cast spells on an array of numbers to produce another number or array of numbers. One ...
• 73.8k
435 views

### Conversions Galore!

Imagine that there are $n$ different types of objects $O_1,O_2,O_3,\ldots,O_n$ and they each have a conversion factor $k_1,k_2,k_3,\ldots,k_n$. You can, for any $1\le i\le n$, convert $k_i$ ...
• 12.7k
897 views

### What is the longest trampoline?

In this challenge we are going to consider lists of integers such that for every member $x$ at index $i$ then the indexes $i+x$ and $i-x$ have the value $x+1$ or are out of bounds for the ...
• 96.5k
2k views

### Construct a diverse array

Given an integer $n \ge 1$, your task is to output an array $a$ consisting of $n^2 + 1$ integers, such that all possible pairs of integers $(x, y)$ satisfying $1 \le x, y \le n$ ...
• 22.3k
1k views

### Longest alternating subsequence

inspired by Longest Increasing Substring Task Given a list of non-negative integers, output the length of its longest alternating subsequence. An alternating sequence is a sequence of numbers which ...
• 73.8k
2k views

### Repeat Values In Array

Given two arrays of non-negative integers $A = [A_1,A_2,\ldots,A_n]$ and $R = [R_1,R_2,\ldots,R_n]$ which are equal in length, return an array which has the element $A_1$ repeated $R_1$ times, ...
• 7,061
2k views

### Reconstruct Matrix from its diagonals

Given the diagonals of a matrix, reconstruct the original matrix. The diagonals parallel to the major diagonal (the main diagonals) will be given. Diagonals: ...
• 8,463