Find HackerRank

Sort by

recency

|

855 Discussions

|

  • + 0 comments

    include

    include

    define HASH_SIZE 100003

    typedef struct Node { long long numerator; long long denominator; long long count; struct Node* next; } Node;

    Node* hash_table[HASH_SIZE] = {NULL};

    // Function to calculate GCD using Euclidean algorithm long long gcd(long long a, long long b) { while (b != 0) { long long temp = b; b = a % b; a = temp; } return a; }

    // Hash function for reduced fraction unsigned int hash(long long a, long long b) { return ((a * 1000003LL + b) % HASH_SIZE); }

    // Insert reduced fraction into hash table void insert(long long num, long long den) { unsigned int idx = hash(num, den); Node* curr = hash_table[idx];

    while (curr != NULL) {
        if (curr->numerator == num && curr->denominator == den) {
            curr->count++;
            return;
        }
        curr = curr->next;
    }
    
    Node* new_node = (Node*)malloc(sizeof(Node));
    new_node->numerator = num;
    new_node->denominator = den;
    new_node->count = 1;
    new_node->next = hash_table[idx];
    hash_table[idx] = new_node;
    

    }

    // Function to count nearly similar rectangles long long nearlySimilarRectangles(int sides[][2], int n) { long long total_pairs = 0;

    for (int i = 0; i < n; i++) {
        long long a = sides[i][0];
        long long b = sides[i][1];
        long long g = gcd(a, b);
    
        long long reduced_a = a / g;
        long long reduced_b = b / g;
    
        insert(reduced_a, reduced_b);
    }
    
    // Count pairs
    for (int i = 0; i < HASH_SIZE; i++) {
        Node* curr = hash_table[i];
        while (curr != NULL) {
            if (curr->count >= 2) {
                total_pairs += (curr->count * (curr->count - 1)) / 2;
            }
            curr = curr->next;
        }
    }
    
    return total_pairs;
    

    }

    // Example usage int main() { int sides[][2] = { {5, 10}, {10, 10}, {3, 6}, {9, 9} };

    int n = sizeof(sides) / sizeof(sides[0]);
    printf("%lld\n", nearlySimilarRectangles(sides, n));  // Output: 2
    
    return 0;
    

    }

  • + 0 comments

    To find HackerRank, simply visit their official website at www.hackerrank.com. HackerRank is a platform that offers coding challenges, competitions, and skill assessments for developers. It provides a wide range of coding problems in various domains like algorithms, artificial intelligence, and databases. You can create an account to access practice problems, participate in competitions, or even apply for jobs. For further details, Wikipedia offers an overview of its features and services.

    In the meantime, while exploring HackerRank, you could also check out panda express menus for a quick and satisfying meal option.

  • + 1 comment

    HackerRank is a leading platform for coding challenges, helping developers sharpen their skills and connect with top employers. Whether you're a beginner or an expert, it offers valuable resources for career growth. For expert real estate services, visit estate agents london today.

  • + 0 comments

    I run a chauffeur service website Farnborough Private Hire chauffeur hire farnborough, and I want to add a booking tool that allows users to:

    Enter pickup/drop-off locations Select a vehicle (e.g., Mercedes S-Class, E-Class) Choose date & time Get an estimated fare Make online payments

  • + 0 comments

    Need a funny, cool, or noble name for your cat? Check this out!