Removing entries from a dictionary containing bad words

I have a dictionary with each item containing a quote in another dictionary: { ‘example1’: {‘quote’: ‘And it must follow, as the night the day, thou canst not then be false to any man.\n’}, ‘example2’: {‘quote’: ‘What a piece of work is man! how noble in reason!.\n’} } I need to completely remove each entry … Read more

Terminated due to timeout Mapping phone numbers

I have a code based on the following problem “Mapping phone numbers to names”, the problem is that when they are going to process large data(+100.000) the program ends by timeout. my code and problem is this, how can I optimize my code to consume less time? my code function processData(input) { var r=input.split(/\n/),o=Number(r[0]),c=r.length-1,x=[]; r.splice(0,o+1); … Read more

Generate JSON for Map>>

Consider I have a String: String value = “Sunday – H15,Sunday – H03,Sunday – H13,Sunday – H01,Sunday – H05,Friday – H23,Saturday – H05,Monday – H16,Monday – H17,Monday – H18,Monday – H19,Monday – H20”; In this String we have Days (Sunday, Monday etc..) and the alphanumeric (H15, H03 etc..) is hours. Now I want a JSON … Read more

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 hash map will hold a key value pair of <int> and <std::set<string>> where the int is the user’s id, and the <std::set<string>> is a set of all instances … Read more

Python Hash Table and insertion

I’m attempting to implement a basic hash table in Python using linked lists. Any tips would be appreciated (including better hash functions). I intend this to handle collisions with separate chaining. I include my gist for my linked list: Question: Are there any things I handled incorrectly or could have implemented in a better way? … Read more

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] Output: 5 Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = … Read more