Skip to content

Conversation

@mariocodecr
Copy link

📝 Pull Request Title

🛠️ Issue

📖 Description

This PR implements a complete solution to the classic "Contains Duplicate" problem in Cairo v1, providing two different algorithmic approaches with comprehensive testing and
documentation.

Key Features:

  • Naive O(n²) approach: Uses nested loops with early exit optimization for simplicity and O(1) space complexity
  • Optimized O(n) approach: Leverages Cairo's Felt252Dict as a hash set for linear time complexity
  • Comprehensive test suite: 21 tests covering all required examples, edge cases, and performance scenarios
  • Production-ready code: Clean, well-documented Cairo v1 with senior-level mentoring comments
  • Educational value: Clear complexity analysis and Cairo-specific implementation notes

Implementation Details:

  • Both approaches work with Span for memory-efficient read-only array access
  • Early exit optimization in both solutions returns immediately when duplicates are found
  • Dict-based approach uses status tracking (0 = not seen, 1 = seen) for efficient duplicate detection
  • All functions handle edge cases: empty arrays, single elements, and various duplicate positions

Required Examples Covered:

  • [1,2,3,1] → true ✅
  • [1,2,3,4] → false ✅
  • [1,1,1,3,3,4,3,2,4,2] → true ✅

🖼️ Screenshots (if applicable)

  • Include any relevant screenshots or examples of the changes made. This helps reviewers visualize the updates
Screenshot 2025-09-03 at 1 17 27 AM

📝 Additional Notes

  • Complexity Analysis: Detailed time/space complexity comparison in README with performance recommendations
  • Cairo Best Practices: Proper use of felt252, Span, and Felt252Dict following Cairo v1 conventions
  • Educational Value: Code includes mentoring-level comments explaining algorithmic choices and Cairo-specific considerations
  • Test Coverage: Comprehensive suite testing base cases, required examples, edge cases, and stress scenarios
  • Documentation: Complete README with usage examples, build instructions, and when to use each approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT]: Contains Duplicate Implementation in Cairo

1 participant