Skip to content

[FEAT]: Contains Duplicate Implementation in Cairo #217

@coxmars

Description

@coxmars

Contains Duplicate Implementation in Cairo

📘 Description

Create an example that implements a solution to the "Contains Duplicate" problem in Cairo. This exercise involves checking if an array contains any duplicate values, which is a common operation in many algorithms and a frequent interview question.

✅ Acceptance Criteria

  • Create an exercises/contains_duplicate folder inside scripts folder and there create a scarb project as the other scripts.
  • Implement a function that takes an array of integers and returns:
    • true if any value appears at least twice in the array
    • false if every element is distinct
  • Implement at least two different approaches:
    • A naive solution (e.g., using nested loops) for educational purposes
    • An optimized solution (e.g., using a set-like structure or sorting)
  • Include comprehensive test cases covering all the examples and edge cases.
  • Document the implementation with clear explanations of both approaches.
  • Compare the time and space complexity of the different approaches.
  • Discuss any Cairo-specific challenges or optimizations.

📚 Examples

Example 1:

Input: nums = [1,2,3,1]
Output: true
Explanation: The element 1 occurs at the indices 0 and 3.

Example 2:

Input: nums = [1,2,3,4]
Output: false
Explanation: All elements are distinct.

Example 3:

Input: nums = [1,1,1,3,3,4,3,2,4,2]
Output: true
Explanation: The array contains multiple duplicate elements.

🌎 References

📜 Additional Notes

  • ⚠ Read our guidelines before applying.
  • This is a beginner-friendly exercise that introduces set-like data structures or sorting algorithms in Cairo.
  • Consider how to efficiently implement a set-like structure in Cairo for checking duplicates.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions