# Questions tagged [data-structures]

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

45 questions
Filter by
Sorted by
Tagged with
496 views

### Double dequer sort

In this challenge Bubbler describes sorting a list by inserting its elements left to right into a double ended queue or "deque". Take a number from the front of the array, and push it into ...
• 99.6k
2k views

### Sorting with a deque

You're given an array of positive integers. Your job is to sort them using an initially empty deque (double-ended queue) by the following procedure: Take a number from the front of the array, and ...
• 78.2k
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 ...
• 10.4k
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
424 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,780
673 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 ...
• 78.2k
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 ...
• 78.2k
285 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
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 ...
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.9k
1 vote
160 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 ...
• 111
736 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.5k
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.9k
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
962 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.9k
306 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
447 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 ...
• 10.5k
920 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
814 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.9k
415 views

### Charlie and the evil hyphen

Here's the phonetic alphabet: ...
• 4,565
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
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 ...
• 30.9k
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.9k
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.9k
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.9k
382 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
437 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
391 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
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.4k
784 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,818
718 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: ...
534 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
649 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 ...
512 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 ...
700 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: ...
424 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 ...
• 146k
380 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
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.9k
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 ...
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
1 vote
815 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
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 ...
600 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 ...
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