Questions tagged [hash-map]

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

Filter by
Sorted by
Tagged with
1 vote
1 answer
67 views

My LRU Cache implementation in Java

...
user avatar
  • 11
0 votes
2 answers
43 views

Shortest way possible to generate javascript string from a large array of values to A, B, C and n others

I have an array of values containing names, e.g. let members = [{id: 1, name: 'Tyler'}, {id: 2, name: 'John'}, {id: 3, name: 'Dayo'}, ..., {id: 7, name: 'George'] ...
user avatar
1 vote
0 answers
41 views

Minimum number of swaps to sort a array, but swaps only allowed with elements 2 apart

I wanted to solve a problem where I sort an array of any size and return the minimum number of swaps. The explanation for the distance 2 is that I choose 3 neighboring elements ABC and then swap them ...
user avatar
0 votes
1 answer
72 views

Sorting Dictionary in a lexicographical order and applying MD5 encryption

I'm sorting a Dictionary in a lexicographical order and applying MD5 encryption. I would like to wrap the sorting somewhere inside the encryption method or so. Official Java example - here Docs <...
user avatar
  • 427
2 votes
2 answers
355 views

C++ Hash table, Hash function, benchmark vs std::unordered_set and std::hash

I wrote my own hash function and my own hash table. My hash function seems to work surprisingly well! Feel free to comment anything! Hash function: ...
user avatar
  • 1,189
3 votes
1 answer
64 views

Langton's Ant cellular automaton in Java

I made a couple of little games and cellular automata in Java. For every new 'game', I used the same code as a base, except for the game logic of course. With every iteration of me customizing my ...
user avatar
3 votes
1 answer
94 views

Implement a Python frozenmap

There are frozenset in Python, but no frozendict or frozenmap. I tried to implement it (Don'...
user avatar
0 votes
1 answer
40 views

How do I increase the memory efficiency of this longest substring implementation? (C++)

I'm practicing my coding on leetcode. I implemented the following algorithm to solve the longest substring problem: ...
user avatar
0 votes
1 answer
39 views

Sudoku puzzle solver for Leetcode

I just solved a problem from leetcode that is faster than 28.42% of the PHP codes, so the main review target is not the performance or alternative ways to solve this problem. I wrote the code thinking ...
user avatar
  • 3
1 vote
0 answers
30 views

Cleanly modifying values in hashmap for a k-sum challenge

Just started learning Rust and here's a program that has caused me some agony to implement in Rust. This is very easy to implement in C++, but Rust's borrow checker is causing all sorts of trouble. My ...
user avatar
  • 33
4 votes
2 answers
248 views

Porting PHP's array_push to Python

I am new to Python but not new to PHP. I've started porting PHP APIs to Python hoping to learn the Python language along the way, currently trying to grasp List, Dict, Set, Tuple. I tried writing PHP'...
user avatar
1 vote
0 answers
78 views

What’s the correct usage of volatile keyword in this Concurrent dictionary implementation?

Can I get some guidance around the usage of volatile keyword and design of the existing concurrent dictionary implementation, please. Here are a few design ...
user avatar
1 vote
1 answer
85 views

The Rust Programming Language book: Company HashMap exercise (Ch. 8)

This is my solution to the third exercise (and last) at the end of chapter 8 of The Rust Programming Language book (https://doc.rust-lang.org/book/ch08-03-hash-maps.html#summary). There are only 3 ...
user avatar
  • 11
0 votes
1 answer
45 views

Calculate session between in and out and total working hours of session

Is there any way to improve this code: punch:0 -> in punch:1 -> out ...
user avatar
0 votes
1 answer
71 views

Calculate working Hours in given shift time

This is simple program to calculate working hours in given shift.. It is also return user sessions and presence of user shift. while this works fine. I would like suggestion to improve it. ...
user avatar
1 vote
1 answer
71 views

Simple Hash Ring Implementation

Introduction I have been reading about Consistent Hashing and in an attempt to better understand the concept, I wanted to implement a simple hash ring. I did not implement the concept of virtual nodes ...
user avatar
  • 1,835
0 votes
1 answer
48 views

Sorting nested dictionary by price - without extra memory

I am working on parsing an orders.csv file with products and prices by different vendors which is kind of a time-series data. The output of that process looks something like below, with order total by ...
user avatar
6 votes
0 answers
58 views

Chapter 8 Challenge: Add employee names to a department

The boring but exciting challenge: Using a HashMap and HashSet, create a text interface to allow a user to add employee names ...
user avatar
  • 61
2 votes
2 answers
153 views

Transforming a list of dictionaries into a dictionary with nested dictionaries

My code takes a list of dictionaries as an input. Each of these dictionaries contains a person identified by name and a region code ...
user avatar
1 vote
0 answers
27 views

Directed weighted graph in C

I am working on a project that requires a directed weighted graph data structure. It looks like this: graph.h ...
user avatar
  • 25.7k
0 votes
1 answer
78 views

Find sets of anagrams in a string array

Below is a program where in which I find groupings of anagrams in a given string array. Is there a better way to do it? ...
user avatar
1 vote
1 answer
84 views

Fastest way to find common keys between many dicts and merge these dicts

I have 1000 dictionaries (grid_1, grid_2.... grid_1000) stored as pickle objects and one ...
user avatar
  • 162
5 votes
1 answer
143 views

Implementation of generic hash table

I am learning how to write generic code in C++ and I decided to write a hash table. Its key needs to be a primitive type and value can be any type. The hash function needs to be provided by the user. ...
user avatar
1 vote
1 answer
96 views

Proper way to transform nested lists to nested maps [closed]

I want to transform a list of lists of lists that I have in a MongoDB document into a map of maps of maps in my java Domain class. The problem I have is that the fields are mixed between the levels. ...
user avatar
  • 121
7 votes
2 answers
1k views

Implementing hash table

I am implementing a program to interact with hash table, the data to be hashed is just number. It works but I want to know if there is any error like: memory leak,... in my code and how to improve my ...
user avatar
  • 147
1 vote
1 answer
31 views

Calculate how many categories I can construct

I would appreciate to have your opinion on this code and whether I can refactor it and make it cleaner. I don't like the fact that I have 3 nested for loops, which ...
user avatar
  • 113
2 votes
2 answers
171 views

Extracting data from dict and processing it

Consider the following ...
user avatar
  • 384
1 vote
1 answer
90 views

How to exclude elements from an array based on a Map while maintaining O(n)?

I am trying to exclude some elements from array items that include properties from array excludes. I wrote this code which works ...
user avatar
3 votes
2 answers
213 views

Parsing a std::string to a dictionary (std::map)

As always - the context ! Preliminaries Recently I needed a way to transport data from one environment to another. Though the proper way (probably) to do this would be to use databases (which I don't ...
user avatar
  • 771
1 vote
2 answers
95 views

Find most occurring word in a sentence

Here is my C code for finding the most occurring word in a sentence: ...
user avatar
  • 286
0 votes
1 answer
59 views

Use an exception to check if item in dictionary [closed]

I am using a KeyNotFoundException to check if an item exists in a Dictionary, creating it when the exception is thrown: ...
user avatar
1 vote
1 answer
43 views

React - Component rendering weather data

Background: Hello, I'm a student (since 2 months) and I've created a small MVP of a weather application. So now I'm refactoring my code because it looks hideous and it is hard to work with. The ...
user avatar
5 votes
1 answer
100 views

Open addressing linear probing hash map

Here is my wheel. strmap - C string hash map. Main goal - create usable and simple alternative to hcreate_r, ...
user avatar
  • 350
3 votes
1 answer
61 views

LetterDict, a dictionary whose keys must be lowercase letters [a-z]

Looking for any suggestions - alternative design, improvements to readability, improvements to the comments, etc. I implemented this letter dictionary to see if it would faster than a regular ...
user avatar
  • 328
2 votes
1 answer
47 views

word frequency distribution

wordList is an array of non-empty strings ("words"). The following code I have written with the purpose of obtaining a Map, containing the unique words ...
user avatar
  • 23
1 vote
0 answers
41 views

Unpack a flattened hash into Hash/JSON

The following JSON ...
user avatar
3 votes
1 answer
133 views

ZigZag Conversion Coding Challenge

This is my solution for ZigZag Conversion, a coding challenge from LeetCode. The challenge: Write a program that takes two parameters, a string and a number of rows, that interprets the string as if ...
user avatar
4 votes
2 answers
214 views

Prioritise injured cats for treatment (dictionary/map search optimization Python and C++)

I am once again attempting another CP problem, and I have ONCE AGAIN run into an optimization issue because of the time limit of one second: https://open.kattis.com/problems/doctorkattis It is common ...
user avatar
  • 141
1 vote
0 answers
43 views

Counting Cram game positions in C

This code counts the number of possible positions in the game of Cram on a mxn board. EDIT 1: In the original question I mistakenly mentioned that this number is ...
user avatar
  • 141
1 vote
0 answers
70 views

A simple Java integer hash set - follow-up

(See the previous version.) (See the next version.) After incorporating changes in the previous post, I came up with this implementation. However, I left hashing as it is. ...
user avatar
  • 25.7k
3 votes
1 answer
113 views

Better way of comparing two lists of dictionaries and display unique changes

Can I get a review of my code which compares 2 dictionaries and display unique changes. ...
user avatar
2 votes
1 answer
188 views

Robin Hood hashing

This is an implementation of a "string to int" hash table with Robin Hood hashing. I have tested it as thoroughly as I could. It appears to have no bugs/leaks. I would appreciate any ...
user avatar
1 vote
1 answer
840 views

Finding nodes with 0 or 1 parents - DFS or BFS

I completed the following question but it seems a lot of space complexity. Do you think is there a way to complete it with graph search or so? Thanks for the comments. Suppose we have some input data ...
user avatar
6 votes
1 answer
393 views

Python function to print a two-column table from a dictionary

I'm currently learning Python for a masters and am trying to improve the best I can, as I'll need to know how to code in my future career. I currently have a function that builds a table from a ...
user avatar
6 votes
1 answer
1k views

friend locator app

I was rejected after a tech screening for the following code. I mainly struggled to make the code 'production ready'. I was running out of time so I did not create a class for testing. How could I ...
user avatar
  • 161
9 votes
2 answers
4k views

Efficient renaming of dict keys from another dict's values - Python

I have a dictionary in Python (uglyDict) that has some really un-cool key names. I would like to rename them based on values from another dictionary (...
user avatar
1 vote
1 answer
61 views

Hashing Table in Python

I just want your opinion about that code! :) ...
user avatar
2 votes
0 answers
74 views

Compute damages and savings for motor insurance claims

I am working on some claims data, where I have features such as The descriptions of the columns are: (A) the year of claim, (B) who's the insuring company (C) whether the vehicle is driven, (D) ...
user avatar
9 votes
3 answers
1k views

The cleanest way to print the max value and its key from a dictionary

I'm getting the highest value and its respective from a dictionary and printing it out for the user. Even though it's working, I'm wondering if I'm doing it in the cleanest way. Here it is: ...
user avatar
  • 369
2 votes
1 answer
62 views

Sports DataSheet

This program asks the user for a players name, # of goals, saves, games played, etc. This information is ten organized on a .txt file along with the time the information was logged. users can also ...
user avatar

1
2 3 4 5
18