Code together.Solvefaster.Level up.
The best way to practice coding challenges with friends, bootcamps, and your dev squad.Crush problems faster together.
Get early access and product updates:

Gamma Code Editor
Two Sum
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
You can return the answer in any order.
Example 1:
Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].
This is a demo to gauge interest. We're developing this collaborative coding platform and want to see if people are interested. If you want updates as we build this product:
Sign Up for Updates1function twoSum(nums, target) {
2 const seen = {};
3
4 for (let i = 0; i < nums.length; i++) {
5 const complement = target - nums[i];
6
7 if (seen[complement] !== undefined) {
8 return [seen[complement], i];
9 }
10
11 seen[nums[i]] = i;
12 }
13
14 return null;
15}
function twoSum(nums, target) {
// Using a map to store values we've seen
const map = new Map();
for (let i = 0; i < nums.length; i++) {
const diff = target - nums[i];
// If we've seen the complement, return both indices
if (map.has(diff)) {
return [map.get(diff), i];
}
// Store current number and its index
map.set(nums[i], i);
}
}
// Brute force approach
function twoSum(nums, target) {
for (let i = 0; i < nums.length; i++) {
for (let j = i + 1; j < nums.length; j++) {
if (nums[i] + nums[j] === target) {
return [i, j];
}
}
}
return null;
}


Key Features
A better way to solve coding challenges together
Our real-time collaborative editor and integrated tools help coding teams learn faster, solve problems more effectively, and track progress together.
š» Real-time Collaborative Editor
Write, run, and debug code together in perfect sync. Multiple cursors, syntax highlighting, and instant updates make pair programming seamless.
š Problem Viewer
Seamlessly import coding problems from LeetCode, HackerRank, and other platforms. Everyone sees the same problem with test cases and constraints.
Given an array of integers nums
and an integer target
, return indices of the two numbers such that they add up to target
.
2
ā¤nums.length
ā¤104
-109
ā¤nums[i]
ā¤109
-109
ā¤target
ā¤109
- Only one valid answer exists.
š Group Progress
Track your team's practice history, achievements, and streaks. See which problems your group has solved and who contributed.
š¤ AI Coding Assistant
Get intelligent code hints, explanations, and optimizations when you're stuck. Our AI helps you understand solutions without giving away the answer.
I notice you're trying to optimize your two-sum solution. Your current approach has an O(n²) time complexity. Have you considered using a hash map to reduce it to O(n)?
I'm not sure how to implement that. Can you explain the hash map approach without giving me the full code?
Sure! With a hash map, you can store each number you've seen and its index.
- Iterate through the array once
- For each number, calculate what value you need to reach the target (target - current)
- Check if that value is already in your map
- If found, you have your pair! If not, add the current number to the map
This way, you only need to go through the array once, giving you O(n) time complexity.