Skip to main content
Build a production-ready coding interview platform where candidates solve problems under time constraints. This cookbook demonstrates how to create a platform similar to LeetCode or HackerRank for technical interviews.

Overview

Coding interview platforms provide a controlled environment for technical assessments. Candidates solve problems within time limits, and the system validates solutions, monitors performance, and generates assessment reports.

Prerequisites

  • HopX API key (Get one here)
  • Python 3.8+ or Node.js 16+
  • Understanding of interview assessment workflows
  • Basic knowledge of performance monitoring

Architecture

┌──────────────┐
│  Candidate   │ Submits solution
└──────┬───────┘


┌─────────────────┐
│  Interview      │ Validate, monitor
│   Platform      │
└──────┬──────────┘


┌─────────────────┐
│  HopX Sandbox   │ Execute & time
└─────────────────┘

Implementation

Step 1: Time-Limited Execution

Execute code with strict time limits:
from hopx_ai import Sandbox
import os
import time
from typing import Dict, Any

class InterviewPlatform:
    def __init__(self, api_key: str):
        self.api_key = api_key
    
    def execute_with_time_limit(self, code: str, time_limit: int, language: str = "python") -> Dict[str, Any]:
        """Execute code with strict time limit"""
        sandbox = None
        start_time = time.time()
        
        try:
            sandbox = Sandbox.create(
                template="code-interpreter",
                api_key=self.api_key,
                timeout_seconds=time_limit + 5
            )
            
            # Execute with timeout
            result = sandbox.run_code(code, language=language, timeout=time_limit)
            
            elapsed = time.time() - start_time
            
            # Check if timeout was exceeded
            if elapsed >= time_limit:
                return {
                    "success": False,
                    "timeout": True,
                    "elapsed_time": elapsed,
                    "time_limit": time_limit,
                    "error": "Time limit exceeded"
                }
            
            return {
                "success": result.success,
                "stdout": result.stdout,
                "stderr": result.stderr,
                "elapsed_time": elapsed,
                "time_limit": time_limit,
                "within_limit": elapsed < time_limit
            }
        except Exception as e:
            return {
                "success": False,
                "error": str(e),
                "elapsed_time": time.time() - start_time
            }
        finally:
            if sandbox:
                sandbox.kill()

# Usage
platform = InterviewPlatform(api_key=os.getenv("HOPX_API_KEY"))

result = platform.execute_with_time_limit(
    code="print('Hello')",
    time_limit=5  # 5 second limit
)
print(result)

Step 2: Performance Monitoring

Monitor code performance:
class PerformanceMonitor:
    def __init__(self, sandbox: Sandbox):
        self.sandbox = sandbox
    
    def monitor_execution(self, code: str) -> Dict[str, Any]:
        """Monitor code execution performance"""
        import time
        
        start_time = time.time()
        result = self.sandbox.run_code(code, timeout=30)
        elapsed = time.time() - start_time
        
        # Get system metrics
        metrics = self.sandbox.get_metrics_snapshot()
        
        return {
            "execution_time": elapsed,
            "code_execution_time": result.execution_time,
            "memory_usage": getattr(metrics, 'memory_usage_mb', 0) if hasattr(metrics, 'memory_usage_mb') else 0,
            "cpu_usage": getattr(metrics, 'cpu_percent', 0) if hasattr(metrics, 'cpu_percent') else 0,
            "success": result.success
        }

# Usage
sandbox = Sandbox.create(template="code-interpreter", api_key=os.getenv("HOPX_API_KEY"))
monitor = PerformanceMonitor(sandbox)

metrics = monitor.monitor_execution("print('Hello')")
print(f"Execution time: {metrics['execution_time']:.2f}s")
print(f"Memory usage: {metrics['memory_usage']}MB")

sandbox.kill()

Best Practices

  1. Time Enforcement: Strictly enforce time limits
  2. Performance Tracking: Monitor execution time and resource usage
  3. Test Case Management: Organize test cases efficiently
  4. Result Reporting: Generate comprehensive assessment reports

Next Steps

  1. Implement problem database
  2. Add candidate authentication
  3. Create assessment dashboard
  4. Implement result analytics
  5. Add video/audio interview features