Welcome, AI Coding Assistant! This guide is specifically for you. It explains how to add new LeetCode problems and visualizations to this repository without breaking the core structure.
AlgoViz is a static Next.js project. To add a new problem, you MUST create/update these 3 files:
- Metadata & Code:
src/data/problems/<slug>.ts - Animation Component:
src/components/visualizations/<slug>/index.tsx - Written Explanation:
src/content/problems/<slug>.mdx
Then, you MUST register the new problem in:
src/data/problems/index.ts(Metadata Registry)src/content/problems/index.tsx(MDX Registry)
Define the problem's metadata using the Problem interface from @/data/schema. Include at least 2 approaches with code snippets for each (TypeScript & Python preferred).
import { Problem } from '../schema';
export const yourProblem: Problem = {
id: 123,
slug: 'your-problem-slug',
title: 'Problem Title',
difficulty: 'Medium',
tags: ['Array', 'Stack'],
leetcodeUrl: '...',
hasVisualization: true,
visualizationComponent: 'YourComponentViz',
approaches: [ ... ]
};Build the React component. Use the useVizStepper hook for playback control and the ArrayViz primitive for standard array animations.
'use client';
import { useVizStepper } from '@/lib/viz-engine/useVizStepper';
import { ArrayViz } from '../_base/ArrayViz';
import { StepController } from '@/components/ui/StepController';
export function YourComponentViz({ nums, target, approach }) {
const steps = useMemo(() => { ... }, [nums, target, approach]);
const { step, controls } = useVizStepper(steps);
return (
<div>
<ArrayViz items={nums} highlights={step.highlights} pointers={step.pointers} />
<StepController {...controls} />
</div>
);
}Write the prose for the problem. You can embed your custom visualization component directly.
# Problem Title
Explain the intuition here.
import { YourComponentViz } from '../../components/visualizations/your-problem-slug';
<YourComponentViz nums={[...]} target={...} approach="..." />- DO NOT modify
src/lib/viz-engine/useVizStepper.tsunless absolutely necessary. - ALWAYS check
src/data/schema.tsbefore writing metadata. - USE
clsxandtailwind-merge(via our@/lib/utilscnhelper) for styling. - NEVER use standard
alert()orconsole.log()in the visualization; handle errors gracefully in the UI.