All Questions
41 questions
5
votes
2
answers
977
views
Optimized data structure mapping finite set of integers to values in C++
I'm looking for a mapping data structure, but knowing that the possible values of my keys are small numbers, I would like to trade memory for better performances (for both random access and value ...
4
votes
3
answers
288
views
Given two sparse vectors, compute their dot product
Problem Statement:
Given two sparse vectors, compute their dot product.
Implement class SparseVector:
SparseVector(nums) Initializes the object with the vector nums
dotProduct(vec) Compute the dot ...
6
votes
1
answer
460
views
Fastest function to `Remove Duplicate Lines` per each cell
The below function is used to Remove Duplicate Lines per each cell.
It works without problem, but it is slow with a range of only one column and 17k rows.
Actually, ...
1
vote
2
answers
72
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']
...
1
vote
1
answer
164
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 ...
4
votes
1
answer
186
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 ...
5
votes
2
answers
329
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'...
1
vote
1
answer
764
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. ...
2
votes
1
answer
91
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 ...
5
votes
1
answer
832
views
Find the shortest sub array that contains all element from 1 to K
I'm trying to solve this problem here. The question is all about finding the shortest sub array inside an array that contains all the element from 1 to K.
Input:
The first line contains three space-...
7
votes
2
answers
814
views
Number of occurrences of strings in array
This is a Hackerrank problem (https://www.hackerrank.com/challenges/sparse-arrays/problem).
We're given an array of strings and an array of queries, and have to return an array of the number of ...
1
vote
2
answers
225
views
Removing duplicate hashes in an array while keeping count of the times the hash was present
I have an array of hashes (price_params['items']) where each item has a key called quantity what I'm trying to do is to clean ...
9
votes
3
answers
1k
views
Creating an affinity-matrix between protein and RNA sequences
I wrote an algorithm that analyzes protein-RNA interactions and I found that the following function is the bottleneck that causes performance issues:
...
3
votes
0
answers
2k
views
Alternative for VLOOKUP/Index-Match in VBA
I am sharing this function I wrote with the community to provide an alternative to slow VLOOKUP and/or Index-...
4
votes
1
answer
425
views
LeetCode: Intersection of two arrays ii C#
https://leetcode.com/problems/intersection-of-two-arrays-ii/
Please review for performance, I am having a problem with using TryGetValue, if someone can explain how this can be used in here.
Given ...