Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [subsequence]

Challenges pertaining to a sequence within a larger sequence

Filter by
Sorted by
Tagged with
26 votes
22 answers
2k views

Reconstruct an arithmetic sequence

Given a finite arithmetic sequence of positive integers with some terms removed from the middle, reconstruct the whole sequence. The task Consider an arithmetic sequence: a list of positive integers ...
20 votes
22 answers
2k views

Sum of Binary Substrings

This challenge is simple, given a decimal number, convert to binary, and calculate the sum of the sub-strings of the binary number, whose length is shorter than the original number. Here is an example:...
15 votes
11 answers
2k views

Make the list Fibonacci-like

Related, but not dupe. Challenge A list of integers \$a_1, a_2, a_3, \dots, a_n\$ (\$ n ≥ 1 \$) is Fibonacci-like if \$a_i = a_{i-1} + a_{i-2}\$ for every \$i > 2\$. Note that every list that ...
5 votes
12 answers
919 views

Even-Odd chunks

(Inspired by the Keg utility of this challenge) Given a non-empty input string, e.g. s c 1= e(a"E"), split the input into even-odd chunks. Example (Feel free to ...
49 votes
54 answers
5k views

Bit run rundown

Given an integer n > 0, output the length of the longest contiguous sequence of 0 or 1 in ...
23 votes
23 answers
3k views

Longest Zero Sum Sub-array

Given an array of integers. Find out its longest sub-array (contiguous subsequence) whose sum is 0. The sub-array for output may be an empty array. Input Input an array of integers. Output Output the ...
29 votes
34 answers
3k views

Backronymiser឵឵

Background A backronym is an acronym that was formed from an existing word. For example, spam is actually named after the canned meat product as used in the Monty Python sketch, but can be ...
33 votes
27 answers
2k views

Stackable sequences

You deal cards labeled 0 to 9 from a deck one a time, forming stacks that start at 0 and count up by 1. When you deal a 0, you place it on the table to start a new stack. When you deal any other ...
23 votes
25 answers
1k views

How many laps around the permutation?

Your input is an array of numbers: a permutation of \$\{1, 2 \dots n\}\$ for some integer \$n \geq 2\$. How many times must you repeat this list before you can "pick out" the numbers \$[1, 2 ...
12 votes
5 answers
439 views

Maximal linear sublists

In this challenge you will write code to take a list of positive integers and output all maximal linear sublists. A sublist is is a list which can be created by deleting values from the the input ...
39 votes
40 answers
5k views

Stretching Words

Write a program or function that duplicates letters in a word, so that all the duplicated letters arranged from left to right in the word would form the input array. For example: ...
20 votes
26 answers
1k views

Column-wise summation of overlapping slices

Task Given a list of integers L and another integer s, the goal is to compute the column-wise sums of all s-length (potentially overlapping) slices of L, while pertaining their positions relative to ...
18 votes
9 answers
541 views

Sliding Capitals

The Background Imagine the English alphabet written out in a row in capital letters -- ABCDEFGHIJKLMNOPQRSTUVWXYZ. Suppose we have a special variable-width lens ...
37 votes
13 answers
2k views

Fractal Smoke Sequence

Introduction A229037 has a quite intriguing plot (at least for the first few terms): There is the conjecture, that it might indeed have some kind of fractal property. How is this sequence ...
46 votes
23 answers
4k views

Is it a circumfix?

Introduction We all know prefixes and suffixes. But there are other types of affixes that exist too. Such as circumfixes, a type of affix that has two parts, one of which is a prefix and another of ...
18 votes
19 answers
4k views

Longest Repeating Subsequence of a Single Digit

Challenge: Given a positive integer, output the longest single-digit subsequence that occurs at least twice, AND has boundaries of another digit (or the start/end of the integer). An example: Input: <...
27 votes
29 answers
2k views

Count edits accounting for grace period

When you edit a post on SE, any further edits within a 5-minute grace period are merged into it. Given a list of times you edit a post, count the edits not in a grace period. Say you edit at minutes <...
9 votes
11 answers
742 views

Otteretto Classic game scoring method

Brief description of the game In the game Otteretto Classic (which you can test directly in your browser; try it!) the player has to form palindromic sequences using adjacent cells on a square grid. ...
15 votes
23 answers
2k views

Find the first run of numbers summing to n

Given as input a positive nonzero integer n >= 10 and a sequence of digits 0-9 (which may be taken as a string or a list), ...
26 votes
34 answers
2k views

Even sum subarrays

Given an array of integers, count the number of contiguous subarrays with an even sum. You may assume that the array is non-empty, and contains only non-negative integers. This is code-golf, so the ...
28 votes
37 answers
3k views

Finding "sub-palindromes".

The shortest code that finds all unique "sub-palindromes" of a string, that is: any substring with length > 1 that is a palindrome. eg.1 ...
44 votes
38 answers
8k views

Speed of Lobsters

From the subreddit r/SpeedOfLobsters: Edit the text of an image to create a new phrase This meme format/style is pretty self-explanatory. Simply have a browse through the subreddit if you need more ...
21 votes
13 answers
2k views

Output every sublist ... eventually

You will be given as input an infinite stream of positive integers. Your task is to write a program which outputs an infinite sequence of lists with two requirements: All lists in the output are ...
18 votes
20 answers
3k views

cadaddadadaddddaddddddr - linked list accessing

Create a function (or closest equivalent, or full program) that takes an list of some datatype (your choice) that may be nested and a string (in either order), and generalizes the lisp c[ad]+r ...
27 votes
3 answers
742 views

Four steps to the left: vipers. Four steps to the right: a cliff. Don't die!

Introduction Suppose for a moment that the vipers and cliff are only two steps away, instead of three. ...
-3 votes
7 answers
1k views

Straight pen strokes for Prime Numbers

Challenge You are supposed to output the series I recently designed which goes as follows which are pen stroke counts of ascending prime numbers: ...
7 votes
6 answers
386 views

Bumping Series Implementation

I have a follow-up question here from my previous question on Math SE. I am lazy enough to explain the content again, so I have used a paraphraser to explain it below: I was considering arbitrary ...
10 votes
17 answers
2k views

Find the largest contiguous prime in a string

In fairness, this is based on a StackExchange question - but its a good question. The challenge is fairly simple: Take a string of numerals Find and print the largest contiguous prime number in the ...
9 votes
8 answers
1k views

Heaviest increasing subsequence

A subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. A strictly increasing subsequence is a subsequence ...
8 votes
18 answers
639 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 ...
25 votes
14 answers
1k views

Collapse consecutive integers

Related: Tell me how many math problems I have to do! Challenge Given a strictly positive strictly ascending integer list L and an integer 3 ≤ N ≤ length of L, replace the middle integers of L's ...
16 votes
17 answers
918 views

Shuffle a subsequence

Thanks to rak1507 for the suggestion "Random" in this challenge always refers to "uniformly random" - of all possible choices, each has an equal chance of being chosen. Uniform ...
14 votes
12 answers
1k views

Count the shared substrings with 2 programs

Write 2 programs in the same language which count the number of shared subsequences of consecutive elements from 2 given sequences. For example, given ...
11 votes
22 answers
2k views

Park, Lake, Santa Fe [closed]

Given a long multi-sentence string, the goal is the count the occurrences of the following words: park, lake, ...
32 votes
31 answers
4k views

Greatest common substring

Create a program or function which takes a list of strings as input, and outputs the longest string that is a substring of all input strings. If there are several substrings of equal length, and no ...
22 votes
20 answers
5k views

Find the odd one out in a sequence

The Challenge: Consider the function F(N) = 2^N + 1 where N is a positive integer less than ...
34 votes
26 answers
4k views

Is there a single straight line in the matrix?

Inspired by Wzl Determine if a given square binary matrix has exactly one row or column consisting of entirely 1s, and the rest of the matrix is ...
32 votes
32 answers
2k views

Decompose binary into alternating subsequences

This was inspired by Problem 13 - Non-Repeating Binary of HP CodeWars' recent competition. Let's take a random decimal number, say 727429805944311 and look at ...
17 votes
9 answers
2k 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 ...
23 votes
29 answers
1k views

Reverse odd runs

Inspiration. Task Reverse runs of odd numbers in a given list of 2 to 215 non-negative integers. Examples 0 1 → 0 1 ...
48 votes
1 answer
5k views

Longest common substring in linear time

This challenge is about writing code to solve the following problem. Given two strings A and B, your code should output the start and end indices of a substring of A with the following properties. ...
33 votes
24 answers
4k views

Bring out the inner llama of a sentence

Your objective is to take input like Pie is good. I just ate a bunch of pies early this morning. Actually, it was closer to the afternoon. Mornings are good. ...
44 votes
22 answers
6k views

Universal Spooky Meme Translator

Introduction Turns out, aliens love memes just as much as we do. Every alien race we've encountered so far has their own version of 2spooky4me (see the following ...
20 votes
2 answers
512 views

Maximal Substring Construction

In this challenge, you are passed two things: A string length, N A list of strings, L, each with an assigned point value. Any ...
30 votes
35 answers
3k views

Is it a fibonacci-like sequence?

The Fibonacci Sequence is a sequence of positive integers where the first two elements are 1 and the rest are the sum of the previous two. It begins \$1, 1, 2, 3, 5, 8, 13\$ and continues forever. But ...
11 votes
7 answers
669 views

Shortest restricted superstring

Given two sets of strings, \$ D \$ and \$ R \$, find the shortest string which contains every string in \$ D \$, but contains none of the strings in \$ R \$. There are almost always multiple possible ...
20 votes
23 answers
3k views

Playing with the musical turtle

My two kids like to play with the following toy: The colored areas with the shapes inside can be touched and the turtle then lights the area and plays a sound or says the name of the color or the ...
25 votes
29 answers
3k views

Make me a metasequence

Background For this challenge, a 'metasequence' will be defined as a sequence of numbers where not only the numbers themselves will increase, but also the increment, and the increment will increase by ...
19 votes
8 answers
2k views

Optimally break a string into words

Given a string, like potatocarrot, break it into the smallest number of substrings possible. These substrings can consist either be a single character, or one of a ...
24 votes
29 answers
3k views

AoCG2021 Day 2: Naughty or nice?

Part of Advent of Code Golf 2021 event. See the linked meta post for details. The story continues from AoC2015 Day 5, Part 2. Santa needs help figuring out which strings in his text file are naughty ...