Skip to main content
Filter by
Sorted by
Tagged with
1 vote
0 answers
135 views

I am trying to solve the following Question: A Power Pokemon Couple is a pair of pokemons with a sum of their power levels equal to a power of two. You are given an array power, containing the power ...
user avatar
-2 votes
3 answers
173 views

I was asked this question in an interview to count the number 1 and 0 in a binary array eg: arr = 1, 1, 0, 1, 0, 1, 0, 0, 0. We should not use Array.sort or Collections.sort function. I could think ...
Mausumi's user avatar
  • 67
2 votes
3 answers
136 views

A HashMap<Integer, Integer> has 10 entries but I only want to print 3 entries. Code: HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>(); hm.put(2, 1); hm.put(5, 3); hm.put(...
user2817235's user avatar
0 votes
2 answers
62 views

I have a following map, which contains basket number to list of fruits in that basket. val basketMap = mapOf("basket1" to listOf("apples", "oranges", "grapes"), ...
NEz's user avatar
  • 163
-1 votes
1 answer
25 views

Consider this data stored in a hashmap: VIN last 4 License plate Details 1234 VehicleObject1 2222 ABC123 VehicleObject2 5678 ABC123 VehicleObject3 5678 XYZ123 VehicleObject4 class VehicleKey{ String ...
Matrix's user avatar
  • 65
0 votes
1 answer
52 views

I have a problem where in a 2D space (x,y) I have a lot of points with different sizes. An array with the struct (x,y, size) represents this space. I want to downsample this space to some specific ...
Iman Fakhari's user avatar
0 votes
0 answers
82 views

I have a space of size ~238 from which I sample a set of ~228 distinct objects (their distribution is structured but hard to characterize). I need a procedure for taking one such sample and ...
cjw's user avatar
  • 1
1 vote
2 answers
111 views

Here is a example: import java.util.HashMap; class Main { public static void main(String[] args) { HashMap<Integer, Integer> a = new HashMap<Integer, Integer>(); a.put(...
HuyWallz's user avatar
0 votes
4 answers
136 views

What is wrong with my code? I'm trying to print the keys but when I print the I'm getting duplicate keys. I was under the impression that when we add duplicate keys to hashmap, it replaces the ...
Akash's user avatar
  • 3
0 votes
1 answer
67 views

I am having an adapter class and there is an instance named 'imageResources' I have declared it lateinit and later I even made it sure that it is given. a value but still I am getting this error ....
kolmikaelson's user avatar
0 votes
2 answers
127 views

I am trying to create a csv file with the headers coming from a map and the values coming from an object. I have a Java object which stores different attribute data. public class MyObject { ...
Mohit224's user avatar
  • 493
-1 votes
2 answers
63 views

Given N 2D Points, Calculate no. of distinct points among them. Ex: x[5] = {2, 1, 3, 2, 2} y[5] = {3, 1, 2, 3, 4} The first array represents the x co-ordinates, the second array represents the y ...
user_program's user avatar
4 votes
1 answer
119 views

I am reading up on distributed hash tables and Kademlia. But I have one pretty big question that I haven't seen answered. Nodes can broadcast their files by hashing the filename and sending it off to ...
Andrew Baker's user avatar
0 votes
1 answer
59 views

I have a HashMap<Character, Integer> that counts the frequencies of letters in a string, called freq. For example, if the word is PUPPY, then the map holds the values {P=3, U=1, Y=1}. I am using ...
CodingNinja's user avatar
1 vote
1 answer
233 views

I tested HashMap retainAll method to test which one is faster with JMH. Two HashMap A, B Size : A > B, A : 300~400, B : 100~200 Most of B elements is in A, so B - A is like 10~20, very small Test ...
박효상's user avatar
2 votes
3 answers
113 views

File zone.csv looks like below: =========================================================== zone0,primaryserver1,primaryserver2,secondaryserver1|secondaryserver2 zone1,primaryserver1,primaryserver2,...
shubhra garg's user avatar
0 votes
2 answers
160 views

I have learned how a hashmap is implemented: an array of linked lists, if separate chaining is used. I know that when a key-value pair (key, val) is inserted, the hashmap inserts the pair {key, val} ...
Christopher Miller's user avatar
-1 votes
4 answers
136 views

It's for a homework assignment so I have to use an Array. I understand using an ArrayList would be the easier solution, but unfortunately I can't. I have a HashMap of animals. I have to create a ...
chalcedony's user avatar
0 votes
1 answer
113 views

I was asked to implement a Fibonacci program that can be reused again. I used a Hashmap below. Just curious, if I should have actually implemented a TreeMap to help performance? I was looking through ...
mattsmith5's user avatar
  • 1,327
-1 votes
1 answer
39 views

I have a Singleton class named ImageStore in which I have declared a Hashmap where value for each is key is a Pair like shown below object ImageStore { val imagesNamesMap = hashMapOf( R....
kolmikaelson's user avatar
0 votes
1 answer
86 views

Problem I have created a tool which runs a code quality analysis tool against all repositories in a shared Gitlab group namespace, and outputs the results to a static site. The tool is structured as ...
vile_goat's user avatar
2 votes
1 answer
1k views

I'm trying to use a HashMap in a very basic way in my struct and I'm confounded by this error ... what am I missing? error[E0277]: the trait bound `HashMap<&str, &T>: Hash` is not ...
user10658782's user avatar
0 votes
1 answer
81 views

I'm attempting to perform multiple lookups into a HashMap. In the program's main loop, my method works just fine. However, once I try to move the logic into a function to hide some messy ...
Lillis's user avatar
  • 3
0 votes
2 answers
106 views

The docs https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html say This class makes no guarantees as to the order of the map; In particular, it does not guarantee that the order will ...
Novice User's user avatar
  • 3,914
2 votes
1 answer
1k views

What's the better option performance-wise if I want to check if an element is contained in a map and use it directly afterwards? std::unordered_map<int, std::string> my_map; int my_key; Option ...
Philip Z.'s user avatar
  • 226
0 votes
1 answer
85 views

So I have this class where I'm trying to initialize a SortedMap using a Comparator I created in another class (separate files) Why is this part not working? Comparator<Map.Entry<Country, Pair<...
Docas 95's user avatar
0 votes
1 answer
114 views

val source = scala.io.Source.fromFile("src/main/Mapping.csv"); val data_map: Map[String, String] = source.getLines().map(csv=> (csv.split(",")(0),csv.split(",")(1)))....
Marcus's user avatar
  • 135
0 votes
1 answer
96 views

If there is a cell configured like this, the desired result is {samsung, [Galaxy S20, Galaxy S21, Galaxy S22, Galaxy S23]}, {apple, [iPhone 13]}, {lg,[g7, g8]} In this way, I would like to obtain ...
user avatar
0 votes
0 answers
79 views

Somehow, in the ranged-based for loop in findLongestPath(), the dfs() function makes it so the loop quits after the first iteration instead of going through every element to pass it to the function ...
Olb's user avatar
  • 1
0 votes
1 answer
40 views

I have a nested HashMap HashMap<String, TreeMap<Integer, Item>>, and now I know the inner key Id(Integer) in TreeMap but don't have the key String in HashMap. Could I use some build-in ...
snow's user avatar
  • 5
5 votes
1 answer
86 views

The signature of HashMap::entry is: pub fn entry(&mut self, key: K) -> Entry<'_, K, V> OK, looks good. I want to take an entry from the HashMap whose key is K, so of course I need to ...
Kodra's user avatar
  • 169
0 votes
1 answer
114 views

I implemented trie by using classes and by dictionaries separately and got different runtimes.Trie implementation with dictionaries worked about 2.5 times faster than trie with classes when input size ...
Ahmet Cicek's user avatar
1 vote
2 answers
66 views

I have a class like public class Values { BigDecimal a; BigDecimal b; } And two maps with the same keys like Map<String, Double> map1 = Map.of("A", 123.1, "B", 345....
Alexander Konev's user avatar
0 votes
1 answer
211 views

I have the following Rust toy code, which is building a global HashMap with closures that return a Struct that is implementing a Trait (please excuse the silly example) pub trait Animal { fn ...
Jaka's user avatar
  • 1,241
1 vote
0 answers
93 views

I'm new to Rust and I'm still struggling with borrowing and move concepts. To set the context, I'm using a library (namely MVT ) that uses following construct to create a layer: let mut tile = ...
Nino's user avatar
  • 441
0 votes
1 answer
155 views

I have a String atp.Status="draft";pureMM.maxOccurs="1";pureMM.minOccurs="1";xml.attribute="true" and want to split it twice and insert it into a HashMap. For ...
matti's user avatar
  • 3
0 votes
1 answer
61 views

Can you help me converting the below logic to make use of streams. This works fine but i want to use streams instead of this List<Map<String, Object>> list1=new ArrayList<>(); List&...
naveen's user avatar
  • 21
0 votes
1 answer
124 views

I'm trying to understand how a bucket(index) is determined in a hashmap by the key and I've read 3 ways to determine it, but there can't be 3. 1) index = hashCode(key) & (n-1) 2) index = hashcode %...
Konstantin's user avatar
0 votes
1 answer
104 views

The Pane (pane - fxml: deadline-example.fxml) has elements (Labels & a pie chart) that are set based on a specific instance of the Deadline class. I also have another scene (deadline-menu.fxml) ...
wan1796's user avatar
2 votes
2 answers
793 views

Example: let mut test: HashMap<HashMap<String, String>, String> = HashMap::new(); test.insert(HashMap::from([("test", "test")]), "test"); The compiler doesn'...
astonius's user avatar
  • 111
1 vote
1 answer
187 views

I'm looking for a way to lookup a word where the user is not smart enough to spell it correctly. I have already handled some cases (like capitalizing the word so it match the string expected on the ...
Antonin GAVREL's user avatar
0 votes
2 answers
188 views

My current attempt: let fruits:Vec<&str> = vec!["Banana", "Peach"]; let fruits_hashmap: HashMap<_, _> = HashMap::from_iter([("Apple", 2),("Banana&...
Antonin GAVREL's user avatar
-2 votes
2 answers
62 views

I am implementing hashmap from scratch. I have my constructor: public MyHashMap(int initialCapacity) { resizeFactor = 2; loadFactor = 0.75; bucketSize = initialCapacity; ...
w97802's user avatar
  • 121
0 votes
2 answers
72 views

I hope all is good for you. I have two maps Map<Type1, Type2> and a Map<Type3, Type1>. I want to merge them and have at the end a Map<Type3, Type2>. How can I do that? I make this ...
Bourg's user avatar
  • 43
1 vote
2 answers
90 views

I am trying to create a map for a tree. It maps the column number (horizontal depth) to the list of nodes with that horizontal depth. When I use the below code, somehow the map gets overwritten by the ...
Bernadette's user avatar
1 vote
1 answer
107 views

I have read somewhere, in context of HashMap : hashCode() allows sorting objects by their hash values, and then the Object#equals method only needs to be invoked when objects share the same hash value....
HyperVol's user avatar
  • 146
1 vote
2 answers
97 views

I am trying to build a sorting algorithm for a few friends of mine, and I am making a test build for it right now. Eventually I will have it more dynamic, but currently I just have it to where it ...
L4w1i3t's user avatar
  • 43
0 votes
1 answer
77 views

Is there something wrong in what I'm doing? I don't understand why the all the map keys are being updated, it should be only the 'ether' key. data := []byte(` [{".id":"*1",&...
Claudiu Mihai's user avatar
1 vote
3 answers
713 views

While solving problems in Python I often had to use Python's collections.Counter object. When I started solving the same problems in C# I couldn't find an equivalent method or class for it. I was just ...
Hammad Ahmed's user avatar
1 vote
2 answers
105 views

I have two different sets of HashMap ({u=0, h=3} and {t=3, i=0}), and it is returning the same hashCode (224). I don't understand this, hashCode needs to be different for different objects, and here ...
Anguraj Dinesh's user avatar

1
3 4
5
6 7
307