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
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 ...
Arnaud's user avatar
  • 8,523
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. ...
user avatar
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 ...
Sara J's user avatar
  • 3,785
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 ...
caird coinheringaahin g's user avatar
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 ...
Itai Ferber's user avatar
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: ...
Stretch Maniac's user avatar
39 votes
27 answers
3k views

Length-terminated sequences

We all know the age-old debate - should strings be length-prefixed or should they be null-terminated? Well, you've run into a blob of binary data and apparently whoever made it decided that the best ...
Sara J's user avatar
  • 3,785
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 ...
flawr's user avatar
  • 43.8k
35 votes
10 answers
2k views

Scroll Word's font size selector

Word's A▲ and ᴀ▼ buttons change the font size according to these rules: The starting font size is 11. If ᴀ▼ is pressed when the font size is 1, the size stays 1. The font size changes with 1 point in ...
Adám's user avatar
  • 30.3k
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 ...
caird coinheringaahin g's user avatar
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. ...
Cilan's user avatar
  • 742
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 ...
xnor's user avatar
  • 145k
32 votes
32 answers
2k views

Subsequence Substitution

Most languages come with a built-in to search a string for all occurrences of a given substring and replace those with another. I don't know of any language that generalises this concept to (not ...
Martin Ender's user avatar
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 ...
Sara J's user avatar
  • 3,785
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 ...
El'endia Starman's user avatar
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 ...
emanresu A's user avatar
  • 38.4k
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 ...
pxeger's user avatar
  • 23.7k
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 ...
Eelvex's user avatar
  • 5,502
28 votes
20 answers
2k views

Pairable strings

A string is pairable if it can be split into subtrings, each of which is a string repeated twice consecutively. For example, aabaaababbbaba is pairable as: ...
xnor's user avatar
  • 145k
28 votes
9 answers
1k views

Collapse the antistring

In this challenge you will be given an alphabetic string as input. We will define the "anti-string" of a given input to be the string with the case of all the letters inverted. For example ...
Wheat Wizard's user avatar
  • 98.8k
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 <...
xnor's user avatar
  • 145k
27 votes
15 answers
2k views

Help pannenkoek count A presses

pannenkoek2012 aims to complete Super Mario 64 with as few presses as possible of the A button, which makes Mario jump. Each "A press" consists of three parts: Pressing the button Holding it for any ...
xnor's user avatar
  • 145k
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. ...
El'endia Starman's user avatar
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 ...
dingledooper's user avatar
  • 22.7k
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 ...
Geza Kerecsenyi's user avatar
25 votes
12 answers
1k views

Find the original string, without the repetition without the repetition in the middle

Sometimes it happens that while typing a sentence, I am distracted and I end up typing the same couple of words twice couple of words twice in succession. To make sure make sure other people are not ...
Qqwy's user avatar
  • 545
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 ...
Adám's user avatar
  • 30.3k
25 votes
7 answers
729 views

Uniquely removable subsequences

Introduction Consider a sequence of integers and one of its subsequences, say A = [4 2 2 4 4 6 5] and B = [2 4 5]. We want to remove the elements of B from A in order, and there are several ways of ...
Zgarb's user avatar
  • 42.7k
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 ...
Bubbler's user avatar
  • 76.7k
24 votes
27 answers
2k views

Check if the string is reshaped

Challenge Given an input string X, determine if X can be obtained from reshaping a strict prefix of itself (a prefix that is not ...
Fmbalbuena's user avatar
  • 3,847
24 votes
20 answers
2k views

Test if a string can be made with substrings!

Given a string s and an array/list l, determine whether or not s can be made with parts from ...
sporkl's user avatar
  • 6,884
24 votes
21 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 ...
DLosc's user avatar
  • 39.5k
24 votes
10 answers
3k views

Where are they calling from?

When making phone calls internationally, phone numbers are prefixed with a code indicating what country the number is located in. These codes are prefix codes, meaning that no code is a prefix of ...
Sara J's user avatar
  • 3,785
24 votes
9 answers
738 views

Smallest number of contiguous monotonic subsequences

A monotonic subsequence is a sequence of numbers \$a_1, a_2, ..., a_n\$ such that $$a_1 \le a_2 \le ... \le a_n \\ \text{or} \\ a_1 \ge a_2 \ge ... \ge a_n$$ ...
shooqie's user avatar
  • 5,652
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 ...
tsh's user avatar
  • 34.9k
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 ...
Adám's user avatar
  • 30.3k
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 ...
lynn's user avatar
  • 68.7k
23 votes
11 answers
2k views

The Ever-Increasing Graph

Consider a one-dimensional sequence of numbers within a fixed range, i.e. [1, 2, 4, 6, 8, 0, 2, 7, 3] in range [0, 10⟩ The Ever-Increasing Graph* ** is a line ...
RvdV's user avatar
  • 333
22 votes
35 answers
1k views

All the k-mers/n-grams

Intro We have had histograms and counting, but not listing all of them. Every year, Dyalog Ltd. holds a student competition. The challenge there is to write good APL code. This is a language agnostic ...
Adám's user avatar
  • 30.3k
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 ...
Ajay's user avatar
  • 621
22 votes
10 answers
1k views

How many Blackjack sequences in that list?

Your task is to find how many distinct Blackjack sequences can be found in an ordered list of 12 cards. A Blackjack sequence is defined as a sequence of consecutive cards whose sum of points is ...
Arnauld's user avatar
  • 193k
22 votes
14 answers
4k views

Remove digits, retaining greater number

Introduction This challenge consists in finding the greatest number removing y digits from the original number n which has x digits. Assuming y=2 n=5263 x=4, the ...
removed's user avatar
  • 2,803
22 votes
2 answers
503 views

Subset Sum Orderings

A set of n positive numbers has 2^n subsets. We'll call a set "nice" if none of those subsets have the same sum. ...
isaacg's user avatar
  • 42k
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 ...
Wheat Wizard's user avatar
  • 98.8k
20 votes
19 answers
2k views

Vandalizing Marquees

A marquee is a low-tech board that allows customizable letters. For example, here is a marquee: SALE ON SNEAKERS However, someone might come along and vandalize it ...
Stephen's user avatar
  • 13.9k
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 ...
Mr. Xcoder's user avatar
  • 42.4k
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 ...
Charlie's user avatar
  • 12.9k
20 votes
19 answers
2k views

Guide my eyes in the right direction

Inspired by this: http://nolandc.com/smalljs/mouse_reveal/ (source). A valid answer: Takes a number \$w\$ and (assumed non-negative) integer \$x\$. Starts with an integer list with a length of \$2^w\$...
Wezl's user avatar
  • 1,478
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:...
GamrCorps's user avatar
  • 7,582
20 votes
13 answers
2k views

Is it a wordinian?

What is the shortest way to see if an input is a wordinian using any programming language? A wordinian is a word that contains words of length 1 to the original word's length. For example, bin ...
Jacques Marais's user avatar