All Questions
31
questions
62
votes
3
answers
4k
views
Analyzing Minesweeper Probabilities
Calculating probabilities in Minesweeper might sound like an easy task, but I've seen so many probability calculators that's either incorrect, horribly slow, or with ugly code (or all of them) so I ...
3
votes
2
answers
1k
views
Premium palindromic primes
Challenge: Write a program which determines the largest prime palindrome less than 1000.
The answer is 929, and my program correctly finds and prints this, but actually ended up being more complex ...
13
votes
8
answers
9k
views
Sieve of Eratosthenes
For practice, I've implemented Sieve of Eratosthenes in Java by thinking about this visual animation.
I would like to hear some suggestions for improvements, especially how to make it more efficient ...
6
votes
3
answers
2k
views
Optimizing unique partitions of integers
I am working on a project involving the unique partitioning of integers. I.e. I am looking to have all of the partitions of n = x1 + x2 + x3 + ... + xk, where xi = xj implies i = j.
For example, if I ...
30
votes
3
answers
27k
views
Perm-Missing-Elem: 100% functional score, but only 60% performance
I cannot figure out why I didn't get 100% success from the Codility's Perm-Missing-Element test even I solve with \$O(n)\$. I will appreciate any advice/answers.
You can see the problem, my code, and ...
11
votes
2
answers
1k
views
Finding an element in multiple sorted lists efficiently
I have \$k\$ sorted Lists, each of size \$n\$. Currently I have hard-coded 5 sorted Lists each of size 3, but in general that is ...
9
votes
4
answers
2k
views
Leetcode : First Missing Positive
I was trying out leetcode's first missing positive.
As per the challenge's description:
Given an unsorted integer array nums, return the smallest missing
positive integer.
You must implement an ...
9
votes
2
answers
3k
views
Finding longest substring containing k distinct characters
Below is my method to find the longest substring having k distinct characters.
I have used Set to keep track of distinct ...
7
votes
2
answers
3k
views
Is this non-recursive mergesort efficient and a good way to simulate the recursive version?
My teacher assigned us to do the recursive version of mergesort, yet I heard that the non-recursive version (bottom up) is a bit tougher, so I decided to this one as well. My main concerns are:
...
7
votes
1
answer
3k
views
How do I optimize this Java cube root function for BigInteger?
I find that this function is one of the biggest causes of slow program execution. I can write a square root version with BigInteger only, but with the cube root, the algorithm sometimes gets caught in ...
7
votes
2
answers
8k
views
External / File-based mergesort
I've implemented an external mergesort to sort a file consisting of Java int primitives, however it is horribly slow (fortunately it does at least work).
Very little happens in the sort method: it ...
6
votes
2
answers
201
views
Name filtering in Java
I have a search box for searching for people in a list of names.
Here is the code that runs every time the query changes. I could not find anything open-sourced for this, so I wanted to make sure ...
5
votes
2
answers
8k
views
Simplified regular expression engine
Task:
On an alphabet set [a-z], a simplified regular expression is much
simpler than the normal regular expression.
It has only two meta characters: '.' and '*'.
'.' -- exact one arbitrary character ...
5
votes
1
answer
182
views
Goldbach conjecture solution finder
The Goldbach conjecture says: any even number greater than two can be represented by the sum of two prime numbers.
G(n) = { (p1, p2) | p1 + p2 = n, p1 and p2 are prime numbers with p1 < p2 }
...
5
votes
2
answers
13k
views
HackerRank Algorithm Challenge 1: Insertion sort
This is my solution for HackerRank's first "Algorithm Challenge, Insertion Sort Part 1". The challenge is to sort the array from least to greatest, the input being an array in sorted order, except for ...