Questions tagged [data-structures]
For challenges involving ways to organize data (hash maps, arrays, binary trees ...)
46 questions
1
vote
2
answers
312
views
minimum line queries in logarithmic time
Input
You are given 2 positive integers, n, q, followed by q queries. the queries can be of two forms:
0 a b: add the line a*x + b. a and b are integers between -...
24
votes
16
answers
3k
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 ...
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 ...
13
votes
10
answers
736
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 ...
12
votes
4
answers
377
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 ...
43
votes
52
answers
3k
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 ...
25
votes
3
answers
806
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 ...
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 ...
7
votes
4
answers
370
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 ...
5
votes
1
answer
1k
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 ...
8
votes
6
answers
501
views
Charlie and the evil hyphen
Here's the phonetic alphabet:
...
15
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 ...
71
votes
66
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] ...
9
votes
2
answers
423
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, ...
20
votes
4
answers
460
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:
...
21
votes
11
answers
862
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 ...
7
votes
3
answers
604
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 ...
18
votes
7
answers
585
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 ...
19
votes
2
answers
458
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 ...
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 ...
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:
<...
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 ...
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 ...