The interactive approach to computer science

Each lesson has interactive puzzles, quizzes, and live simulation to make the learning process as seamless as possible.

Logic circuit

XOR from NAND

Sorting

Merge sort

51 lessons · 4 folders

Learn step by step

A short stack of lessons for everything computer science, fully interactive and fun.

Browse all tutorials

Try them out

Tools & visualizers

9 interactive tools that each do one job, free in the browser, and every one of them embeddable with the Embed button on its tile.

Browse all tools

Sorting Visualizer

Seven algorithms, one frame at a time, with the comparisons and writes counted underneath.

Open
Algorithm
0
comparisons
0
writes
0 / 18
in place

Quick sort: pick a pivot, move everything smaller to its left, then recurse on each side.

Step 1 of 98

K-map Solver

Cells to 1 or don't-care; the minimal sum-of-products falls out.

Flowchart Maker

Add boxes, connect them, layout is automatic.

Number Bases

Flip a bit and watch binary, decimal and hex move together.

Open
One byte, click a bit to flip it
1286432168421
Binary
10110110
Decimal
182
Hex
0xB6
1234

Topological Sort

Kahn's algorithm a node at a time, in-degrees falling as it goes.

?

K-map Practice

A fresh random map every time. Group it yourself and find out if it is minimal.

Graph Traversal

Play or scrub a BFS or DFS; the queue and the visited order keep up.

Open
Example
ABCDEFG

Click any node to start the traversal from there.

Queue (first in, first out)
A
Visited, in order

nothing yet

Start at A. The queue holds the nodes we know about but haven't looked at yet, so A goes in first.

Step 1 of 9

Coding problems

Try a coding problem

Implement one function in Python, JavaScript or C++, run it against the worked examples, then submit it against the hidden cases.

Browse all problems

Two Sum

Easyarraystwo pointers

Find the two numbers in a sorted array that add up to a target.

You are given an array numbers sorted in ascending order, and an integer target. Return the indices of the two values that add up to the target, smallest index first.

Constraints

  • 2 ≤ numbers.length ≤ 10,000
  • -10⁹ ≤ numbers[i] ≤ 10⁹
  • numbers is sorted in ascending order
  • assume exactly one pair works

Examples

Input
numbers = [2,7,11,15], target = 9
Output
[0,1]
Why
numbers[0] + numbers[1] = 2 + 7 = 9.
Input
numbers = [2,3,4], target = 6
Output
[0,2]
Why
2 + 4 = 6. Note that 3 + 3 is not allowed - that would reuse one element.
Input
numbers = [-3,3,4,90], target = 0
Output
[0,1]
Why
Negative numbers behave no differently.

Submitting also runs 6 hidden tests.

Open the full problem
Loading the editor

Logic problems

Try a logic problem

Pick one, wire up the inside of the chip, and run the tests in the real editor below.

Browse all problems

Writing

Read articles about CS

Longer pieces on the ideas the tutorials only have room to use.

Read the blog