Title: Two Sum in Ruby - Runnable Code Snippet
Open Graph Title: Two Sum in Ruby - Runnable Code Snippet
X Title: Two Sum in Ruby - 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 Ruby 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 Ruby 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 Ruby snippet with live execution.
Keywords:
Opengraph URL: https://tempercode.dev/snippets/two-sum-ruby
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":"Ruby","text":"seen = {}\nresult = nil\narr.each_with_index do |num, i|\n complement = target - num\n if seen.key?(complement)\n result = [seen[complement], i]\n break\n end\n seen[num] = i\nend\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