मुख्य कंटेंट तक स्किप करें

Interactive Code Editor Sandbox

knoxiboy
EditReport

Interactive Code Editor Sandbox

Edit and run algorithm code samples directly in your browser. Select your preferred language, modify the code, and click Run Code to see the output instantly. Use the 👁 Preview button to view syntax-highlighted code, and 🔄 Reset Code to restore the default template.

Features

FeatureDetails
Multi-language supportJavaScript, Python, C++
In-browser JS executionconsole.log output captured live
Syntax highlightingKeywords, strings, numbers, comments
Reset CodeRestores the default algorithm template
Output consoleInline output panel with error messages

Live Sandbox

Binary Search — JavaScript

Language Notes

JavaScript ✅ Full In-Browser Execution

JavaScript runs directly in the browser sandbox using new Function(). All console.log and console.error output is captured and displayed in the output panel below the editor.

Time Complexity for Binary Search: O(logn)O(\log n)

function binarySearch(arr, target) {
let lo = 0, hi = arr.length - 1;
while (lo <= hi) {
const mid = Math.floor((lo + hi) / 2);
if (arr[mid] === target) return mid;
else if (arr[mid] < target) lo = mid + 1;
else hi = mid - 1;
}
return -1;
}

Python 🐍 (Pyodide Integration)

Python execution requires Pyodide — a WebAssembly port of CPython. The sandbox currently simulates Python output and shows guidance to integrate Pyodide for full in-browser execution.

Time Complexity for Merge Sort: O(nlogn)O(n \log n)

def merge_sort(arr):
if len(arr) <= 1:
return arr
mid = len(arr) // 2
return merge(merge_sort(arr[:mid]), merge_sort(arr[mid:]))

C++ ⚙️ (Server-Side Compilation)

C++ requires compilation. The sandbox displays submitted code and guidance to use the Compiler Explorer API for server-side execution.

Time Complexity for Quick Sort: O(nlogn)O(n \log n) average, O(n2)O(n^2) worst

void quickSort(vector<int>& arr, int lo, int hi) {
if (lo < hi) {
int p = partition(arr, lo, hi);
quickSort(arr, lo, p - 1);
quickSort(arr, p + 1, hi);
}
}
Track Your Progress

Done with this topic? Mark it as complete to track your progress.