Title: Two Sum in JavaScript - Runnable Code Snippet
Open Graph Title: Two Sum in JavaScript - Runnable Code Snippet
X Title: Two Sum in JavaScript - Runnable Code Snippet
Description: Find indices of two numbers in an array that add up to a target value using a hash map for O(n) time complexity. Runnable JavaScript snippet with live execution.
Open Graph Description: Find indices of two numbers in an array that add up to a target value using a hash map for O(n) time complexity. Runnable JavaScript snippet with live execution.
X Description: Find indices of two numbers in an array that add up to a target value using a hash map for O(n) time complexity. Runnable JavaScript snippet with live execution.
Keywords:
Opengraph URL: https://tempercode.dev/snippets/two-sum-javascript
Domain: tempercode.dev
{"@context":"https://schema.org","@type":"SoftwareSourceCode","name":"Two Sum","description":"Find indices of two numbers in an array that add up to a target value using a hash map for O(n) time complexity.","programmingLanguage":"JavaScript","text":"const map = new Map();\nlet result = null;\nfor (let i = 0; i < arr.length; i++) {\n const complement = target - arr[i];\n if (map.has(complement)) { result = [map.get(complement), i]; break; }\n map.set(arr[i], i);\n}\nreturn result;"}
| theme-color | #0c0d12 |
| color-scheme | dark |
| author | Temper |
| creator | Temper |
| publisher | Temper |
| og:image | https://tempercode.dev/og-image.png |
| og:type | article |
| twitter:card | summary_large_image |
| twitter:image | https://tempercode.dev/og-image.png |
Links:
Viewport: width=device-width, initial-scale=1