Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

Questions tagged [array-manipulation]

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

Filter by
Sorted by
Tagged with
0
votes
0answers
229 views

Reconstruct a video where the frames' pixels have been shuffled [sandboxed] [closed]

Please give feedback in the sandbox version if you want to improve this question. Thanks! Given a video where all the pixels of every frame have been scrambled with some image scrambling function T(...
16
votes
14answers
2k views

Unique magic triplets

Description Your input is a list of integers \$[a_1, \dots, a_n]\$. A magic triplet is a triplet \$(a_i, a_j, a_k)\$ of values from this list, such that the indices \$\{i, j, k\}\$ are all distinct,...
9
votes
8answers
334 views

1D Shikaku Validation

Shikaku is a 2D puzzle. The basic rundown of it is that a rectangular grid has some numbers in it, and you want to partition the grid into rectangular components such that each component contains ...
1
vote
1answer
136 views

Minimum number of changes required [closed]

Given an array where each number represent a color. After iterating each item in the array (for each item in the iteration the pointer can also point to the second-item-to-the-right), and the two ...
0
votes
1answer
123 views

Shooting gallery Puzzle!

Have you been shooting gallery? We are recently. In our shooting gallery cans and aluminum cans from under various drinks hang and stand. More precisely, they hung and stood. From our shots, banks ...
11
votes
18answers
2k views

It's as easy as 1,2,3 (except you have to add them up)

Let's consider a list \$L\$ (initially empty) and a pointer \$p\$ into this list (initialized to \$0\$). Given a pair of integers \$(m,n)\$, with \$m\ge 0\$ and \$n>0\$: We set all uninitialized ...
5
votes
6answers
261 views

Explore a Klarner-Rado sequence [duplicate]

One of the Klarner-Rado sequences is defined as follows: the first term is \$1\$ for all subsequent terms, the following rule applies: if \$x\$ is present, so are \$2x+1\$ and \$3x+1\$ the sequence ...
15
votes
43answers
3k views

Find the percentage

We haven't had any nice, easy challenges in a while, so here we go. Given a list of integers each greater than \$0\$ and an index as input, output the percentage of the item at the given index of the ...
4
votes
7answers
158 views

Replace by most recent nonzero [duplicate]

Given a non-empty list of decimal digits (0, 1, ..., 9), replace each zero by the most ...
3
votes
1answer
143 views

Highest cardinality grouping of contiguous integers with minimum-sum threshold

Challenge Given an array of positive integers and a threshold, the algorithm should output a set of consecutive-element-groupings (subarrays) such that each group/subarray has a sum greater than the ...
-6
votes
11answers
176 views

Return the nth element of an array even if its out of bound [closed]

The challenge Write a function that returns the nth element of an array even if its out of bound. ...
22
votes
24answers
4k views

Count the number of triangles

Given a list of positive integers, find the number of triangles we can form such that their side lengths are represented by three distinct entries of the input list. (Inspiration comes from CR.) ...
30
votes
29answers
2k views

The Lucky House

There's a minigame in Super Mario 3D World known as the Lucky House. It consists of a slot machine with 4 blocks. Each block may be one of 5 different icons (Flower, Leaf, Bell, Cherry or Boomerang) ...
-5
votes
2answers
137 views

Elimination ordering

Your task is to remove smallest amount elements from a list, so the most elements are on their corresponding place. The element is on it's corresponding place, when it's value is equal to it's ...
9
votes
7answers
1k views

An array battle with odd secret powers

Here is a relatively simple two dimensional array challenge. Imagine a battlefield of 625 foot soldiers. You command the odd troops, but unfortunately the strength of the even troops overwhelms you. ...
11
votes
34answers
1k views

Chunk + Enumerate a list of digits

I have a list of decimal digits: 4, 4, 4, 7, 7, 9, 9, 9, 9, 2, 2, 2, 4, 4 The list of decimal digits are known as items. We can form "chunks" from these items by ...
10
votes
7answers
242 views

Crossing sequences

Crossing Sequences Given a list of positive integers A, call it an increasing sequence if each element is greater than or equal to the previous one; and call it a ...
5
votes
7answers
196 views

Dropsort with a Twist

This is my first attempt at a Code Golf question. If it needs obvious edits, please feel free to make them. Below is a description of the basic Dropsort algorithm. Dropsort is run on a list of ...
2
votes
3answers
153 views

Golf range minimum queries of a list [closed]

(Inspired by the first problem solved in Stanford’s advanced data structures course.) Despite the academicese-heavy name, the problem we're going to solve is almost unbearably simple. We have a list ...
34
votes
11answers
1k views

There's an echo in my array… echo in my array… my array

Help! I seem to have an annoying echo in some of my arrays, and I'd like to get rid of it. When this occurs, the original array repeats itself somewhere in the middle causing the values to be added ...
21
votes
17answers
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 ...
14
votes
9answers
973 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 ...
13
votes
4answers
441 views

Distributing parliament seats

Introduction In a general election, one would like to calculate a constant price per parliament seat. This means that for N >= 0 seats to be distributed and a ...
3
votes
3answers
173 views

Find longest consecutive characters in 2D array

Challenge Given a 2D array, find the length and direction of all the longest consecutive characters. If there are ties, output every possible winning combination in any order, (winners can overlap ...
11
votes
6answers
913 views

Group Integers by Originality

Introduction: I collect twisty puzzles. Most twisty puzzles are produced and sold by Chinese companies. Most well-known companies ask permission from puzzle designers to produce their designs and ...
14
votes
31answers
2k views

Incremental Ranges!

Your task is to, given two positive integers, \$x\$ and \$n\$, return the first \$x\$ numbers in the incremental ranges sequence. The incremental range sequence first generates a range from one to \$...
4
votes
9answers
267 views

Maximum summed sub sequences with no two numbers sharing the same digit [closed]

Suppose there are 5 positive integers in an array or list as 14, 12, 23, 45, 39. 14 and 12 cannot be taken in the subset as 1 is common in both. Similarly {12, 23}, {23, 39}, {14, 45} cannot be ...
16
votes
37answers
2k views

Split into three!

Given a string, you've to split it into groups of three characters (by padding _ at the end). Related, but still it's different. Sample I/O: ...
10
votes
2answers
300 views

Golf my Ada arrays

Background Ada is a programming language that is not exactly known for its terseness. However, its array literal syntax can in theory allow for fairly terse array specifications. Here is a simple ...
10
votes
10answers
681 views

Determine if a grid contains another grid

Challenge Create a function takes in two 2-dimensional arrays of Characters (or Strings if the programming language does not have characters as a datatype) as inputs: a and b. If your language does ...
3
votes
4answers
424 views

Intercommunication between threads [closed]

So glad I found this cool site. Wanted to try sharing a coding challenge a friend gave me, an interview question. Usually it is written in java, but you can use whatever language you want, just have ...
17
votes
23answers
1k views

Enumerate Derangements

Given some positive integer \$n\$ generate all derangements of \$n\$ objects. Details A derangement is a permutation with no fixed point. (This means in every derangement number \$i\$ cannot be in ...
-2
votes
6answers
249 views

Map values to any multidimensional array [closed]

Codegolf challenge - mapping values in a multidimensional array [ [0, 0, 0], [0, 0, 0], [0, 0, 0] ] This 2D array is sick of being so false, and wants to ...
23
votes
20answers
1k views

Maximum summed subsequences with non-adjacent items

Introduction: Inspired by these two SO questions (no doubt from the same class): print the elements in the subarray of maximum sum without adjacent elements java and Maximum sum of non adjacent ...
21
votes
12answers
1k views

Slither Like a Snake

The Idea We've done matrix spirals before, and full rotations, and even diagonal rotations, but not, as far as I can find, snake rotations! What is a snake rotation? Imagine the rows of a matrix ...
19
votes
10answers
484 views

Reorder a Master List Based on a Reordered Subset

I recently had a problem to solve at work where I had two lists: a master list, and a smaller list that contains a subset of the items in the master list potentially in a different order. I needed to ...
10
votes
6answers
650 views

Consistent Overhead Byte Stuffing (COBS)

I'm surprised this hasn't been posted before! The Consistent Overhead Byte Stuffing (COBS) algorithm is used to delimit byte streams. We choose a frame marker (we'll use 0x00) and wherever 0x00 ...
28
votes
19answers
2k views

Rotate a column

Given an integer k and either a block of text, or a 2d array that the inner arrays may have unequal lengths (that resembles a block of text), rotate every character or element in the k-th column up or ...
17
votes
26answers
854 views

Calculating total slots

Given a list of jobs, which must be done in order, with each taking a slot to do, how long will it take to perform them all if after doing a job the same job cannot be done for the next two slots (...
-2
votes
1answer
226 views

Morse sudo-ku-de

Hehe, see what I did with the title? Anyways... Your job is to create a sudoku solver that accepts input in Morse code and creates output in Morse code. Here's the Morse code numbers for reference: <...
40
votes
30answers
3k views

Print a physical multiplication table

Rectangles have this nice property - an \$n \times m\$ rectangle consists of exactly \$n \times m\$ characters! A.. more interesting property is that the rectangles can be aligned nicely in a ...
31
votes
23answers
8k views

Could you please stop shuffling the deck and play already?

Challenge: Input: A list of distinct positive integers within the range \$[1, \text{list-size}]\$. Output: An integer: the amount of times the list is riffle-shuffled. For a list, this means the ...
15
votes
22answers
3k views

Deal the cards to the players

Tonight is card game night! You are the dealer and your task is to write a program to deal the cards to the players. Given an array of cards and the number of players, you need to split the array of ...
21
votes
38answers
3k views

Create chunks from an array

Your task is to write a program which given an array and a number, you need to split the array into chunks with size is number. Rules Your program will receive an array ...
9
votes
13answers
629 views

Arrays Start at \$\pi\$

Your task is to take an array of numbers and a real number and return the value at that point in the array. Arrays start at \$\pi\$ and are counted in \$\pi\$ intervals. Thing is, we're actually going ...
20
votes
46answers
2k views

Count repetitions of an array

You will receive an array and must return the number of integers that occur more than once. [234, 2, 12, 234, 5, 10, 1000, 2, 99, 234] This will return 2, since ...
16
votes
7answers
2k views

Borderless table

In this challenge you are going to place letters from the alphabet in a Cartesian plane and output the result as a text. Your input will consist in a list of list with 3 parameters: X coordinate Y ...
43
votes
23answers
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]...
21
votes
23answers
3k views

Pointer jumping

Suppose we have an array \$\texttt{ps}\$ of length \$n\$ with pointers pointing to some location in the array: The process of "pointer jumping" will set every pointer to the location the pointer it ...