Skip to main content
Back to Samples
EasyCompleted

Two Sum Problem

Array manipulation with hash map optimization

A+
Overall Grade
Performance Overview
Time Taken
8 minutes
Complexity Accuracy
Perfect
Edge Cases Discussed
Yes
Alternative Solutions
Discussed
Your Solution
function twoSum(nums, target) {
    const map = new Map();
    
    for (let i = 0; i < nums.length; i++) {
        const complement = target - nums[i];
        
        if (map.has(complement)) {
            return [map.get(complement), i];
        }
        
        map.set(nums[i], i);
    }
    
    return [];
}
Optimal O(n) time complexity
Clean, readable code structure
Proper edge case handling
AI Feedback
Strengths
  • • Immediately identified optimal hash map approach
  • • Excellent explanation of time/space complexity
  • • Discussed edge cases proactively
  • • Clean, production-ready code style
Additional Insights

Your solution demonstrates strong algorithmic thinking. You correctly identified that the brute force O(n²) approach could be optimized using a hash map for O(n) lookup time.

Detailed Performance Metrics
Problem Understanding95%
Code Quality98%
Communication92%
Actions