easy+150 XPFrontend AlgoArena
Two Sum in O(n) Time
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
What it has to do
- Return indices as an array
[i, j]. - Must run in O(n) time using a Map / Hash Object.
- Return empty array if no pair exists.
Your workspace
Try it yourself· Edit the code, then press Run
Loading playground...
Ready to check it?
2 tests run against your code, right here in your browser. Sign in to claim the XP when you pass.
AI Crack & Solution Assist
Stuck? Get instant AI hints or break down the optimal solution.