I have to create a custom hash-table that uses linear probing for collision resolution. The hash table stores a vector of structs. The struct stores the pair for each (key, value) which are templated along with a status for empty, occupied, and deleted. I am having trouble with my insert function using the std::hash() function ..

#### Category : hashmap

I’m trying to create an algorithm in C that given a list of integers, finds 2 pairs of integers that have the same product (a x b) = (c x d), where a,b,c,d are different integers, with the range of numbers being from 1 to 1024. After a bit of research, I came across this ..

This is the problem statement i don’t understand what is the problem with the map function is not as I am expecting can I am expecting "abaca" and I am getting "abc". string rearrangeString(string str) { //Your code here. map<char,int> mp; int i; int l=str.length(); for(i=0;i<l;i++) { mp[str[i]]++; } int j=(l/2)+1; i=0; string s=""; map<char,int>::iterator ..

my code: class Solution { public: int lengthOfLongestSubstring(string s) { if(s.length()==0){ return 0; } unordered_map<char, int> map; int j=0,c=0,x=c,st=0; for(int i=0;i<s.length();i++){ if(map.find(s[i])==map.end()){ map[s[i]]++; x++; continue; } else{ auto it1=map.find(s[j]); auto it2=map.find(s[i-1]); map.erase(it1, it2); j++; i=j-1; if(x>c){ c=x; x=0; continue; } } } if(x>c){ c=x; } return c; } }; and getting the following error: Line ..

I was solving the question- In a array nums of size 2 * n, there are n + 1 unique elements, and exactly one of these elements is repeated n times. Return the element repeated n times. Constraint: 0 <= nums[i] < 10000 4 <= nums.length <= 10000 int repeatedNTimes(vector<int>& nums) { // long long ..

I am curious about insert function in hashmap data structure using singly linked list if only considering the hashmap is blank if (ht[hash_val] == NULL) { } , which hash_val is the int value calculate from hashfunction, and ht is the hash table which is already constructed while the insert function is insert(key k, value ..

So, I can very easily initialize a hashmap from int to vector… But can I initialize that vector with a size and maybe default values ?? For example : vector<int> a(2,0) <–Size and values are initialized …. So is there something for unordered_map<int, vector<int>> Source: Windows Que..

I wanted to create a hashmap with the key as a pair but of the pair values is of a struct that I have defined. Something like below. unordered_map<pair<node*,int>,int> m; The compiler is throwing an error. What am I doing wrong. If this is not possible is there an alternative? error is – /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/unordered_map.h:141:7: note: ..

Following is the code for Minimum time requirement problem Link to the question here ->link I do not understand the following part,specifically what is curr_time – map in the following code.In do understand what curr_time is but that "curr_time-map" i don’t get it. // the above approach #include <bits/stdc++.h> using namespace std; // Function to ..

def recursiveDict(): return collections.defaultdict(recursiveDict) # I can create a dictionary like the following dic = recursiveDict() dic[‘a’] = 1 dic[‘a’][‘a’] = 1 dic[‘a’][‘a’][‘a’] = 1 dic[‘a’][‘a’][‘a’][‘a’] = 1 and so on…. I have returned to work with C++ after working for 4 years with Python and other dynamic languages. I wanted to be able to ..

## Recent Comments