Skip to content

Instantly share code, notes, and snippets.

View coderRohan123's full-sized avatar
🎯
Focusing

Rohan Mallick coderRohan123

🎯
Focusing
View GitHub Profile
@coderRohan123
coderRohan123 / Duplicate Number Checker.md
Created January 1, 2024 09:34
This code checks if a list of numbers contains any duplicates by using a set to keep track of numbers that have been seen before. It returns True if there are duplicates, and False otherwise.

Duplicate Number Checker

Preview:
# The original implementation has a time complexity of O(n), where n is the length of the input list nums.
# This is because each number in nums is checked against the set of seen numbers, which has an average time complexity of O(1) using hash-based set implementation.

# The implementation is already quite efficient, and there is not much room for performance improvement. However, we can make a small modification to potentially improve the average case performance.

# Revised implementation:
def contains_duplicate(nums):
@coderRohan123
coderRohan123 / Matrix Rotation 90.md
Last active January 1, 2024 09:33
This code snippet rotates a square matrix 90 degrees clockwise by reversing the rows and then transposing the matrix in-place.

Matrix Rotation 90

Preview:
def rotate(matrix):
    n = len(matrix)

    # Reverse the rows
    matrix.reverse()

    # Transpose the matrix in-place