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

Questions tagged [data-structures]

For challenges involving ways to organize data (hash maps, arrays, binary trees ...)

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

Implement a bag without replacement

Intro The Tetris Guidelines specify what RNG is needed for the piece selection to be called a Tetris game, called the Random Generator. Yes, that's the actual name ("Random Generator"). In ...
bigyihsuan's user avatar
  • 9,448
8 votes
33 answers
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 ...
U13-Forward's user avatar
  • 2,001
14 votes
10 answers
417 views

CGAC2022 Day 17: Present Heap

Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details. Inspired by https://xkcd.com/835 In the midst of his mid-life crisis, Santa has impulsively purchased a Sports ...
Ginger's user avatar
  • 5,500
13 votes
10 answers
665 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 ...
Bubbler's user avatar
  • 76.7k
20 votes
25 answers
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 ...
Bubbler's user avatar
  • 76.7k
12 votes
4 answers
282 views

Is it a heapable sequence?

A binary max heap is a rooted tree with integer labeled nodes such that: No node has more than 2 children. The label of every node is greater than all of its children. We say a sequence of integers ...
cjquines's user avatar
  • 1,231
2 votes
1 answer
1k views

An Scalable Event Scheduler That Can Handle Billions of Events [closed]

The event scheduler is a recurrent theme in event-driven architectures: something triggers an event that needs to be checked in the future one or more times. I has particular use in trading where you ...
user avatar
40 votes
51 answers
2k views

Follow a linked list

For this challenge, a linked list looks like this: [1, 2, 4, 0, 6, 1, 3, 1] You'll notice there's no data; each item in the list is just a reference to the index ...
Rydwolf Programs's user avatar
1 vote
1 answer
158 views

Building a Structured Outline [closed]

In a fictional document management system, input documents are structured with weighted headings. Lowest weighted headings are the most important. This is a sample document: H1 All About Birds H2 ...
Tlink's user avatar
  • 111
25 votes
3 answers
705 views

Drawing a tree from an array

Given a possibly nested, non-empty array of single-digit positive integers (not guaranteed unique), output the ASCII-art representation as a tree, using the box-drawing characters ...
AdmBorkBork's user avatar
  • 43.4k
48 votes
85 answers
8k views

Implementing a stack

I can't believe we don't have this already.. It's one of the most important data-structures in programming, yet still simple enough to implement it in a code-golf: Challenge Your task is to ...
ბიმო's user avatar
  • 16.8k
17 votes
31 answers
2k views

Search text for a prefix and list all its suffixes in the text

I use "suffix" loosely here to mean "any sub-string that follows the prefix". "Prefix" here means the START of a word, where a word's start is defined as either after a space or from the first ...
DrQuarius's user avatar
  • 640
17 votes
7 answers
955 views

Binary tree rotations

Balanced binary search trees are essential to guarantee O(log n) lookups (or similar operations). In a dynamic environment where a lot of keys are randomly inserted and/or deleted, trees might ...
ბიმო's user avatar
  • 16.8k
7 votes
4 answers
300 views

Regrowing trees

Background Here you have another work-inspired challenge, but from my wife's work in this case. Imagine you have a service that returns the list of nodes in a tree structure (much like the files and ...
Charlie's user avatar
  • 12.9k
12 votes
10 answers
445 views

Disentangle doubly linked data

A doubly linked list is a data structure in which each node has a value as well as "links" to both the previous and next ...
Jordan's user avatar
  • 10.1k
5 votes
1 answer
878 views

Decode my I2C Stream!

From the sandbox! I2c or TWI, is a 2 way stream that uses 2 signal lines: SDA and SCK. This is used in sensors to communicate ...
tuskiomi's user avatar
  • 3,831
9 votes
11 answers
808 views

Squaring Off (fit to smallest possible square)

Intro More complex than A square of text since this requires padding and input has unknown data type. Every year, Dyalog Ltd. holds a student competition. The challenge there is to write good APL code....
Adám's user avatar
  • 30.3k
8 votes
6 answers
410 views

Charlie and the evil hyphen

Here's the phonetic alphabet: ...
rybo111's user avatar
  • 4,547
29 votes
8 answers
5k views

Should we be friends?

Note this is a question primarily focusing on data-structures Introduction Bacefook wants people to be friendlier! As such, they are implementing a new system to suggest friends! Your task is to help ...
Thunda's user avatar
  • 1,199
14 votes
6 answers
1k views

Evaluate a simple spreadsheet

Rules No cell range references (A2:B3). Maximum 9 rows and 9 columns. No circular references or formula errors. Empty cells evaluate to ...
Adám's user avatar
  • 30.3k
13 votes
19 answers
1k views

Simple CSV/DSV importer

Slightly more than an inverse of this. In: Multi-line DSV data and a single delimiter character. The DSV may be taken as a file, a filename, line-break separated string, list of strings, etc. ...
Adám's user avatar
  • 30.3k
68 votes
61 answers
7k views

N-dimensional N^N array filled with N

In: Enough memory and a positive integer N Out: N-dimensional N^N array filled with N, where N^N means N terms of N-by-N-by-N-by... Examples: 1: [1] ...
Adám's user avatar
  • 30.3k
22 votes
17 answers
2k views

Neutralize data

To neutralize data, recursively replace all numbers (not digits!) with zeros and all characters (not strings!) with spaces. You must accept any single number, character, or string, or possibly ...
Adám's user avatar
  • 30.3k
9 votes
2 answers
370 views

Compute the height of a radix tree

Introduction A radix tree, also known as compressed trie or compressed prefix tree, is a tree-like data structure for storing a set of strings. The edges of the tree are labeled by nonempty strings, ...
Zgarb's user avatar
  • 42.7k
9 votes
1 answer
429 views

Flexagonal flexagation

Being programmers, watching us flex aren't very interesting. Today we change that! In this challenge you will lex and flex hexaflexagons. About For a video introduction, watch viharts video(s) on ...
BlackCap's user avatar
  • 3,928
20 votes
4 answers
389 views

Validate a stem-and-leaf plot

A stem and leaf plot displays a bunch of numerical values in groups, which are determined by all but the last digit. For example, suppose we have this set of data: ...
Ben N's user avatar
  • 1,713
15 votes
15 answers
3k views

Is it a max-heap?

A heap, also known as a priority-queue, is an abstract data type. Conceptually, it's a binary tree where the children of every node are smaller than or equal to the node itself. (Assuming it's a max-...
DJMcMayhem's user avatar
  • 59.2k
20 votes
11 answers
777 views

Implement bag operations

A bag, also called a multiset, is an unordered collection. You can call it a set that allows duplicates, or a list (or an array) that is not ordered/indexed. In this challenge, you are asked to ...
busukxuan's user avatar
  • 2,808
24 votes
1 answer
715 views

Stack Exchanging

Problem Say you have N stacks named S1 through SN, where each Sk (k = 1 to N) contains N copies of the number k. For example, when N = 3 the stacks looks like this: ...
Calvin's Hobbies's user avatar
6 votes
3 answers
526 views

Shortest class to implement Perl hash-of-hashes

At some point, I bumped into an SO question asking how to implement Perl's trivial hash-of-hashes data structure in Java. For those who don't know Perl, the hash value can be a scalar or another ...
DVK's user avatar
  • 251
13 votes
7 answers
645 views

Prefix Tree Traversal

Write a program that takes in (via stdin or command line) a string with the recursive form PREFIX[SUFFIXES] where PREFIX may ...
Calvin's Hobbies's user avatar
18 votes
7 answers
511 views

Numbering Hierarchical Outlines

Write a program that takes in a string where every line consists of the character 0 indented by some number of spaces. The top line is not indented and every other ...
Calvin's Hobbies's user avatar
5 votes
1 answer
698 views

Most efficient table storage for determining recurrence

The goal of this challenge is to implement a storage and retrieval pattern that will most quickly determine if a set of recurrence definitions fall within a date range. Consider the schema: ...
RichardTheKiwi's user avatar
19 votes
2 answers
421 views

Turn over a new leaf

You're given a tree, which in computer science tradition, has the root at the top and leaves at the bottom. The leaf nodes are labelled with numbers. Your goal is to take the special leaf marked ...
xnor's user avatar
  • 145k
5 votes
2 answers
379 views

Heaps of trouble

Challenge You must, in the least bytes possible, implement the Binary Heap data structure and each of the following methods that operate on it: A function which takes no arguments and returns an ...
globby's user avatar
  • 1,190
6 votes
2 answers
1k views

Collatz Graph Plotting [closed]

Write a program that outputs a graph of the collatz sequence any way you want (ASCII Image Video etc). You have to implement it that way that you can adjust the size of the graph by either the maximum ...
flawr's user avatar
  • 43.8k
2 votes
1 answer
325 views

Immutable dictionaries in Haskell [closed]

You need to implement immutable dictionaries using only functions without any other data types (custom or built-in). The dictionary must be indexed by any data type of class Eq and contain values of ...
Curly Brace's user avatar
6 votes
11 answers
5k views

Generate the python dictionary of phone keypresses for any letter

In the fewest bytes, generate the dictionary of keypresses for any letter (as described in https://code.google.com/codejam/contest/351101/dashboard#s=p2) In Python, the dictionary literal itself: <...
dspyz's user avatar
  • 933
1 vote
8 answers
814 views

Build a numerical library without using any primitive data type

The task is to build a numerical library for working with arbitrarily large integers that supports the following operations: addition subtraction multiplication division modulo operation However, ...
Petr's user avatar
  • 4,360
5 votes
4 answers
1k views

Shortest implementation of a linked list, stack and queue

Challenge Write the shortest program that implements the minimum requirements for a linked list, stack and queue. Minimum requirements Functions that allow the user to add and remove elements from ...
user avatar
-5 votes
2 answers
598 views

Strings: Microsoft interview

You are given an array of strings , you have to construct a single array containing all of them so that the same array of strings can be reconstructed from the large array. The strings may contain any ...
user227541's user avatar
21 votes
9 answers
2k views

Implement lazy lists, preferably in a language you don't know well [closed]

This is a nice exercise for becoming more fluent in that programming language you've been meaning to learn, but have only tinkered with lightly. This involves working with objects, using or ...
Joey Adams's user avatar
  • 10.6k
3 votes
2 answers
402 views

Implement cdbmake

Write the shortest program to build a cdb database, using the following syntax for input: +klen,dlen:key->data followed by a newline. Example: ...
C. K. Young's user avatar
  • 4,937