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
0 votes
1 answer
51 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: ...
MrSynAckSter's user avatar
0 votes
1 answer
177 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 ...
Chubby Cows's user avatar
4 votes
2 answers
231 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 ...
eof's user avatar
  • 193
5 votes
2 answers
308 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'...
hanshenrik's user avatar
1 vote
0 answers
230 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 ...
Dhruv Sawhney's user avatar
1 vote
1 answer
167 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 ...
spketre's user avatar
  • 11
0 votes
1 answer
138 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 ...
1258259's user avatar
0 votes
1 answer
571 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. ...
1258259's user avatar
1 vote
1 answer
292 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 ...
Jae Bradley's user avatar
  • 1,845
0 votes
1 answer
300 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 ...
Prashanth kumar's user avatar
6 votes
0 answers
89 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 ...
lml's user avatar
  • 61
2 votes
2 answers
994 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 ...
Vivek gaud's user avatar
1 vote
0 answers
56 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 ...
coderodde's user avatar
  • 27k
0 votes
1 answer
226 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? ...
Sreedhar Danturthi's user avatar
1 vote
1 answer
582 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 ...
skynaive's user avatar
  • 162
5 votes
1 answer
551 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. ...
fbi open_up's user avatar
1 vote
1 answer
618 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. ...
Paplusc's 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 ...
Becker's user avatar
  • 147
1 vote
1 answer
32 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 ...
yosra's user avatar
  • 113
2 votes
2 answers
229 views

Extracting data from dict and processing it

Consider the following ...
Sito's user avatar
  • 384
1 vote
1 answer
1k 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 ...
noobie's user avatar
  • 111
3 votes
2 answers
1k 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 ...
LRDPRDX's user avatar
  • 781
1 vote
2 answers
121 views

Find most occurring word in a sentence

Here is my C code for finding the most occurring word in a sentence: ...
ndogac's user avatar
  • 286
0 votes
1 answer
301 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: ...
Bart Friederichs's user avatar
1 vote
1 answer
68 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 ...
Jonathan Manner's user avatar
5 votes
1 answer
138 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, ...
JulStrat's user avatar
  • 350
3 votes
1 answer
82 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 ...
joseville's user avatar
  • 446
2 votes
1 answer
481 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 ...
Jada's user avatar
  • 23
1 vote
0 answers
71 views

Unpack a flattened hash into Hash/JSON

The following JSON ...
Samuel Vijaykumar's user avatar
3 votes
1 answer
320 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 ...
Tim_Jarvis99's user avatar
4 votes
2 answers
345 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 ...
CoderTang's user avatar
  • 141
1 vote
0 answers
48 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 ...
martin's user avatar
  • 141
1 vote
0 answers
78 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. ...
coderodde's user avatar
  • 27k
3 votes
1 answer
1k 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. ...
Samuel Traxler's user avatar
2 votes
1 answer
507 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 ...
Aykhan Hagverdili's user avatar
1 vote
1 answer
2k 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 ...
Neslihan Bozer's user avatar
6 votes
1 answer
1k 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 ...
Ramen Enthusiast's 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 ...
MosesA's user avatar
  • 161
10 votes
2 answers
7k 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 (...
Noah Broyles's user avatar
1 vote
1 answer
64 views

Hashing Table in Python

I just want your opinion about that code! :) ...
KermitTheFrog's user avatar
2 votes
0 answers
75 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) ...
Ravindra Rao's 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: ...
ARNON's user avatar
  • 401
2 votes
1 answer
78 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 ...
Grewal_Creator's user avatar
1 vote
1 answer
49 views

I have a query like this that seems complicated and I want to do it by using Java Stream Api

I have method that fetches sorted and filtered data from Mysql Database, Firstly I had done It by using Java. Now I did it by Mysql but I don't like the way the code looks I have entity that named ...
Justtoasktheneededquestions's user avatar
2 votes
1 answer
285 views

Implementing hash table in Python using Tuples

I am trying to implement a basic hash table using a list of tuples. The code produce the desired output. Please help me improve my code as I feel there are a lot of while loops. ...
Raghav Bhalla's user avatar
5 votes
2 answers
1k views

Hashmap implementation in C++

I have been asked to implement a HASHMAP in C++ in a job interview (home assignment). I'm a bit unsure about exception safety, but this is what I came up with: Block.h ...
Joshua Goege's user avatar
2 votes
0 answers
552 views

3Sum - leetcode

Question: Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0. Notice that the solution set ...
Joseph Gutstadt's user avatar
0 votes
0 answers
77 views

Is this a good way to construct the class for a C++ template partial specialisation of a member function?

I am teaching myself c++ by doing a series of exercises. I liked the idea of working out how hash tables could be done using just the language and no std calls. I discovered that you cant do "...
StoneMonkeyMark's user avatar
7 votes
2 answers
4k views

Income tax rate calculator in c++

I have been trying to learn c++ for the sake of being comfortable with a second language. I found a project that seemed relatively easy, although it may not be implemented perfectly, it was a simple ...
stupidQuestions's user avatar
2 votes
1 answer
189 views

Hash Table implementation in C using linear probing for collisions

I've written a simple Hash Table implementation in C, in order to use it in an IRC bot, so mostly storing nicknames, channel names, etc (small strings). I'm using linear probind to resolve collision. ...
Thibaut D.'s user avatar

1
2
3 4 5
19