# Questions tagged [data-structures]

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

43 questions
Filter by
Sorted by
Tagged with
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] ...
• 30.4k
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 ...
• 16.8k
2k views

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 ...
• 18.7k
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 ...
• 1,199
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 ...
• 9,726
712 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 ...
• 43.4k
717 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: ...
• 89.8k
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 ...
• 30.4k
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 ...
• 10.6k
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 ...
• 76.9k
778 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 ...
• 2,808
390 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: ...
• 1,713
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 ...
• 145k
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 ...
• 89.8k
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 ...
• 640
956 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 ...
• 16.8k
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-...
• 59.3k
418 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 ...
• 5,650
1k views

Rules No cell range references (A2:B3). Maximum 9 rows and 9 columns. No circular references or formula errors. Empty cells evaluate to ...
• 30.4k
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. ...
• 30.4k
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 ...
• 76.9k
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 ...
• 89.8k
445 views

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 ...
• 10.1k
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 ...
• 1,231
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....
• 30.4k
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, ...
• 42.7k
430 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 ...
• 3,928
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
410 views

### Charlie and the evil hyphen

Here's the phonetic alphabet: ...
• 4,567
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 ...
• 12.9k
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: <...
• 933
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 ...
• 43.8k
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 ...
• 251
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 ...
892 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 ...
• 3,831
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 ...
• 1,190
699 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: ...
403 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: ...
• 4,937
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 ...
326 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 ...
1 vote
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, ...
• 4,360
1 vote