DSA Visualizer

Interactive, step-by-step visualizations of popular data structures and algorithms. Select a problem below to see how the algorithm executes in real-time.

Two Sum

Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.

3Sum

Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.

4Sum

Given an array nums of n integers, return an array of all the unique quadruplets [nums[a], nums[b], nums[c], nums[d]] such that: 0 <= a, b, c, d < n, a, b, c, and d are distinct, nums[a] + nums[b] + nums[c] + nums[d] == target.

Container With Most Water

You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that together with the x-axis form a container, such that the container contains the most water.

Binary Search

Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1.

Valid Parentheses

Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

Maximum Subarray

Given an integer array nums, find the subarray with the largest sum, and return its sum.

Maximum Depth of Binary Tree

Given the root of a binary tree, return its maximum depth. A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

Breadth-First Search (BFS)

Breadth-first search (BFS) is an algorithm for searching a tree data structure for a node that satisfies a given property. It starts at the tree root and explores all nodes at the present depth prior to moving on to the nodes at the next depth level.

Climbing Stairs

You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

Sudoku Solver

Write a program to solve a Sudoku puzzle by filling the empty cells. (Visualized using a 4x4 grid for clarity).

N-Queens

The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other. (Visualized with N=4 for clarity).

Rat in a Maze

Consider a rat placed at (0, 0) in a square matrix of order N * N. It has to reach the destination at (N - 1, N - 1). Find all possible paths.

Aggressive Cows

Given an array of stalls and k aggressive cows, place the cows such that the minimum distance between any two of them is maximized.

Cycle Detection in Linked List

Given head, the head of a linked list, determine if the linked list has a cycle in it.

Network Delay Time

You are given a network of n nodes, labeled from 1 to n. You are also given times, a list of travel times as directed edges times[i] = (u_i, v_i, w_i). We will send a signal from a given node k. Return the minimum time it takes for all the n nodes to receive the signal.

M Coloring Problem

Determine if it's possible to color a graph with M colors such that no two adjacent vertices have the same color.

Search Suggestion System

Given an array of strings products and a string searchWord, return a list of lists of the suggested products after each character of searchWord is typed.

Construct Tree from Pre & Postorder

Construct a binary tree from its preorder and postorder traversals and return its root.