Questions tagged [hash-map]

A data structure that uses a hash function to map identifying values, known as keys, to their associated values

3
votes
1answer
54 views

Hashing array of strings as Merkle tree in one function

I want to hash an array of strings into one hash as shown on scheme on the image below. But I do not want to implement some class based Merkle tree. It's just a simple function. Is this a good ...
2
votes
0answers
65 views

Coding Challenge Solution - Find Number of Elements in a range in \$O(1)\$ with preprocessing

Overview This is my solution to the following Coding Challenge - Find Num of Elements in a Range in \$O(1)\$ with Preprocessing - Given an array and max element in the array, find the number of ...
0
votes
2answers
56 views

Creating a Java text-based game map [closed]

i got a college project and i'm trying to create a map for my text-based game in Java. Me and my colleague* created this code: ...
4
votes
2answers
291 views

How to set an interval to std::map [closed]

This code belongs to a contest. I tried to apply the range of data to a std::map. The contest system however warns me that the implementation of the assign function ...
3
votes
1answer
92 views

Hash table in Python

...
0
votes
1answer
91 views

java.util.Set extension/implementation

Lately, I was working on some experimental java.util.Set extension, IdSet: ...
2
votes
0answers
30 views

Convert flat object hierarchy to json

I do work for a project currently, where the data is send to the server as application/x-www-form-urlencoded (which is bad, and it should be JSON, but unfortunately I am not able to change this one). ...
0
votes
1answer
40 views

Generating probability table of 2-character combinations from text file in Java

I have written a probability table generator in Java to help me generate randomized girl's names for the game I am making. It reads from a text file and creates a ...
7
votes
1answer
1k views

Sort int array by frequency then value

Problem Take an array of ints as input and run a special sorting algorithm on it. This algorithm must first sort by int frequency, less frequent first, then sort by value. For example ...
0
votes
1answer
84 views

Implementation of a Hash Map in C++

I created a templated Hash Map class in C++, which supports most of the basic C++ types (e.g. int, float, ...
1
vote
2answers
248 views

Quick & Simple Hash Table Implementation in C

First time implementing a hash table. I resolve collisions using the separate chaining method (closed addressing), i.e with linked lists. The hash function used is: ...
4
votes
2answers
378 views

Data Structures for Counting Duplicates and using std::vector::erase

Problem Dupe detection for a vector of ints. I simply want a count of the unique input characters that occurred at least twice. The goal is to count a dupe only once and ignore that input character ...
5
votes
2answers
733 views

sorting a map by converting it to vector

I have a map that I want to print out sorted by value, I convert it to vector and sort the vector. Is this code correct? ...
1
vote
2answers
131 views

HashMap implementation, is this good enough for interviews?

After understanding HashMaps, I decided to implement my own using 3 classes HashMap, LinkedList, and Node. I knew how to implement LinkedList from before. Can you please give me feedback on this. ...
1
vote
1answer
43 views

Turn a list of words into a dictionary

I am looking for a way to turn a list of words that may have duplicates into a dictionary/map that counts the number of occurrences of words. After spending some time with the problem, this seems to ...
0
votes
1answer
90 views

HashMap Implemention in Java

I just finished implementing a HashMap in Java, with methods: add(String key, Integer value) get(String key) ...
-3
votes
1answer
58 views

Reducing function calls with Map [closed]

Currently I am working on reducing function calls in my tool. My function is called add_field_and_calc ...
2
votes
1answer
32 views

case…when or Hash#fetch [closed]

I have the following method, which can be written in the following two ways: which one would you prefer, and why? ...
0
votes
2answers
472 views

C++ - Hash map implementation using smart pointers

I am trying a simple Hash Map implementation in c++. I have used this and this as reference. The implemented design uses a class HashEntry to manage individual key-...
1
vote
0answers
54 views

Using HashMaps to track parent and rank of graph nodes

I often find myself in the following position: I have created a class in some file, and would like to add a new data member to that class without changing the original class definition. Now, you ...
3
votes
2answers
69 views

Return Kth to Last: Implement an algorithm to find the kth to last element of a singly linked list

Implement an algorithm to find the kth to last element of a singly linked list. Any comments or feedback regarding this? I came up with another algorithm that uses ...
1
vote
1answer
365 views

Frequency Queries hackerrank [closed]

This is the problem: You are given queries. Each query is of the form two integers described below: - 1: Insert x in your data structure. - 2: Delete one occurrence of y from your data ...
3
votes
1answer
135 views

Buy and Sell a Stock for maximum profit (given a day and a price)

If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit. Example one: Input: [7,1,5,3,6,4] ...
4
votes
1answer
173 views

Tracking the number of string elements using std::unordered_map

I'm looking for the most simple and efficient way to track the number of string elements in a container. Previously, I used std::vector but I tried changing the ...
-4
votes
1answer
70 views

Use key as object in map C++: Check if the less operator is implemented correcty [closed]

Hello I wrote the following code. It allows me to use objects as keys in a map. I have a constraint though: In addElement function both arguments must be pointers ...
5
votes
0answers
181 views

HashMap exercise, Rust book Ch.8

I'm learning Rust by learning the Rust programming language book. I'm now implementing the solution for the third challenge. Using a hash map and vectors, create a text interface to allow a user to ...
2
votes
2answers
64 views

Chinese mapping number routing

I want to design Chinese mapping number routing. How can I improve this code in the method mapRouting? I want to use reflect auto get method name by providing a ...
4
votes
1answer
1k views

Hackerrank Day 8: Dictionaries and Maps solution in C++

This is a solution for the Day 8 hackerrank.com challenge. The basic idea of the challenge is to create a mapping of names to phone numbers based on the the given input, and later look up the phone ...
1
vote
0answers
208 views

Ruby Hash to XML

I've just made this "serialization" module in Ruby that takes a hash and outputs a XML string. ...
0
votes
1answer
835 views

Custom LinkedHashMap Implementation

I implemented my own LinkedHashMap in java. ...
4
votes
2answers
2k views

Spell Checker program using dictionary implementation

This is a small program written for a small assignment to check spelling. The assignment asks for the following output: A list of words that are misspelled in the file A count of the ...
5
votes
1answer
81 views

Number base manipulation in Haskell

I am picking up good Haskell practices! In this instance, I wanted to pick a file which contains a title in the first line and then every line is a string. Each string represents a number in base ...
12
votes
3answers
2k views

Determine if one string is a permutation of the another

Can anyone give me some feedback if I'm using std::unordered_multimap optimally? I don't know the ins-and-outs of the ...
6
votes
1answer
2k views

Hash table with separate chaining implementation in C

I'm attempting to implement a hash table with separate chaining in C. It works fine, but is there something that I should optimize, fix or maybe add some features? ...
1
vote
0answers
159 views

java - A* search algorithm

I'm having trouble with my homework implementing A* search algorithm in java, I'm given the graph, origin and destination, I had to follow some specific tasks in the homework so the code might be a ...
1
vote
2answers
3k views

Custom HashMap Implementation in java

I implemented a CustomHashMap in Java, and would like to know if my approach is good or not. Below I am sharing the complete code of my ...
0
votes
1answer
836 views

It is a hashmap, using linear probing on an array

I have been studying hashtable for two days and was musterring up the courage to write a code. Finally I have written code in which I have taken many shortcuts: The first being I have used ...
1
vote
1answer
893 views

Find the most frequent number in an array

I implemented a solution for: Finding the most frequent number from an array. How are my variable names? Or how could I improve this? ...
1
vote
2answers
112 views

Finding duplicates in arrays

I'm given two sorted arrays, arr1 and arr2. They can either be of the same length or arr2 ...
1
vote
2answers
74 views

Given a list containing dates and the amount spent on each date, display the total amount spent per month

I had an interview yesterday where I was asked to write a function that would take in a list containing a date and the amount of money spent on that date, and to output the total amount spent per ...
2
votes
3answers
258 views

Find the first reoccuring char from a String

Can anyone give me advice on how I can improve my answer? I have tested it out using "ABCA", "BCABA" and "ABC". Two things I would like help on. 1.How can I move this code into a method where it ...
9
votes
4answers
9k views

HashMap implementation in Python

Here's my implementation of a bare-bones HashMap in Python. Expected behavior, it returns None if a key is missing, When a key is inserted the second time it just overwrites the first value. ...
1
vote
1answer
544 views

Put ages within a supplied range into a HashMap

I'm looking for general considerations to make for the next time I'm writing code. I'm wondering if in this case it's better to have another auxiliary storage (another map?) in this case (and how to ...
4
votes
1answer
169 views

Simple form validation module

Thinking about form validation, I just wanted something simple that works and is extensible. I came up with the following code, which expects a list of selectors that maps to one or more functions ...
1
vote
0answers
375 views

constexpr hashtable string to user type

This creates something like constexpr mar<String, T> using C++14. Collision resolution is with static_assert and manually ...
2
votes
3answers
862 views

HashMap implementation in Java

I have implemented a hash map in Java, using generics. Let me know if I can improve it. ...
3
votes
1answer
1k views

Thread safe tbb::concurrent_hash_map and std::set

I have a basic websocket server implemented in C++. I'm using Intel TBB's concurrent hash_map to store all the users, uniquely identified by the id. The concurrent ...
2
votes
2answers
595 views

Parse a formatted string, which may have duplicate keys, into a map

I have a String which is coming in particular format so I want to parse that string into map. I have a below method which parses String to a Map and it works fine. ...
3
votes
1answer
218 views

Counting subsets with sum not exceeding some limit

I am facing a variation of a subset sum problem. I have to count the number of subsets with sum less than or equal to some integer(limit). I think the optimal solution for this problem would be the ...
3
votes
1answer
262 views

HashMap in Javascript

I began working on a Javascript project, and the first fundamental building block is a data structure that mimics Java's java.util.HashMap, since Javascript ...