< Nafees />
github
  • Assignments - DSA
  • Long Integer Operations
  • OOP
    • Introduction
    • Implementation
  • Sorting Algorithms
    • Selection Sort
    • Bubble Sort
    • Insertion Sort
    • Shell Sort
    • Shuffle
    • Merge Sort
    • Convex Hull
    • Quick sort
    • System Sort
    • Heap-Sort
  • Binary Search
  • Binary Search By Recursion
  • Two-Pointer
  • String
  • LeetCode 75
    • Array/String
    • Hash Map
    • BST
    • Binary Search
  • Top Interview 150
    • Linked-List
  • Leetcode Programming Skill
    • Math
  • Leetcode 75
  • 🤡Leet Code Extra
  • Arrays
    • 1-D Array
    • 2-D Arrays
  • 👨‍🍳Basic Math - Codechef
  • ☠️Recursion
  • 😁Public Member Functions
    • Strings Functions
  • 👾Linked List
    • What's Linked List & Implementation?
      • Singly Linked List
      • Doubly Linked List
    • Problems
  • 📚Stack
    • What's Stack & Implementation?
      • Stack Using Array
      • Stack using LL
    • Problems
  • 🏧Queue
    • What's Queue & Implementation?
      • Simple Queue
      • Queue using LL
      • Circular Queue
      • Deque using Linked List
      • STL Deque
    • Problems
  • 🏧Priority Queue
    • What's Priority Queue & Implementation
      • OrderedArrayMaxPQ.Java
      • Maximum-Oriented PQ using Binary Heap
      • Minimum-Oriented PQ using Binary Heap
    • Problems
  • 🗓️Hash Table
    • What's Hash Table & Implementation
      • ST - Seperate Chaining
      • ST - Linear Probing
    • Problems
  • 🎴Symbol Table
    • What's Symbol Table and implementation
      • ST Using Binary search (ordered array)
      • ST Using Binary Search Tree
      • ST Using Left-Leaning Red-Black Tree
      • ST Using Hash Table
    • Problems
  • 🔗Union-Find (Dynamic Connectivity problem)
    • What is a Union Find Data Structure?
    • Implementation
  • 🎋Binary Tree
    • What's Binary Tree & Implementation?
      • Traversal
      • Red-Black BST
  • 🌴Trie
    • What's Trie & Implementation?
    • Problems
  • 😎Project
    • Expression Evaluation
Powered by GitBook
On this page
  • Q1: Find the Difference of Two Arrays
  • Q2: Equal Row and Column Pairs 79/80 :)

Was this helpful?

  1. LeetCode 75

Hash Map

PreviousArray/StringNextBST

Last updated 9 months ago

Was this helpful?

Q1:

class Solution {
public:
    bool uniqueOccurrences(vector<int>& arr) {
        unordered_map<int, int> mp;
        unordered_map<int, int> mp2;

        for(int i = 0; i < arr.size(); i++) { 
            if(mp.find(arr[i]) != mp.end()) 
                mp[arr[i]]++;
            else
                mp[arr[i]] = 1;
        }

        for(auto it = mp.begin(); it != mp.end(); it++) {
            if(mp2.find(it->second) != mp2.end())
                mp2[it->second]++;
            else
                mp2[it->second] = 1;
        }

        for(auto it = mp2.begin(); it != mp2.end(); it++) {
            if(mp2[it->first] >= 2) 
                return false;
        }

        return true;
    }
};
class Solution {
public:
    int equalPairs(vector<vector<int>>& grid) {
        
        unordered_map<int, int> rowMap;
        unordered_map<int, int> colMap;

        for(int i = 0; i < grid[0].size(); i++) {
            int sum = 0;
            
            for(int j = 0; j < grid[0].size(); j++) sum += grid[i][j];
            rowMap[i] = sum;
        }
        
        for(int i = 0; i < grid[0].size(); i++) {
            int sum = 0;  
            
            for(int j = 0; j < grid[0].size(); j++) sum += grid[j][i];
            colMap[i] = sum;
        }

        int countSum = 0;

        for(int i = 0; i < grid[0].size(); i++) {

            for(int j = 0; j < grid[0].size(); j++) {
                
                if(rowMap[i] == colMap[j]) {
                    bool isEqual = true;

                    for(int k = j; k < grid[0].size(); k++) {

                        if(grid[i][k] != grid[k][j]) isEqual = false;
                        
                    }
                    if(isEqual) countSum++;

                }   
            }
        }

        return countSum;
    }
};

Q2: 79/80 :)

Find the Difference of Two Arrays
Equal Row and Column Pairs