Skip to main content

All 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 ...
Simon Forsberg's user avatar
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 ...
quartaela's user avatar
  • 505
29 votes
5 answers
12k views

Custom indexOf() without String methods

I created my own indexOf function. I was wondering if anyone could help me come up with a way to make it more efficient. I am practicing for interviews so the catch ...
Liondancer's user avatar
  • 1,499
16 votes
1 answer
205 views

Minesweeper analyze goes to N-Queensland

As @rolfl recently solved the N-Queens problem, I figured that it was time also for me to solve it. My approach is significantly different from @rolfl's. I quickly realized that the N-Queens problem ...
Simon Forsberg's user avatar
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 ...
John R's user avatar
  • 303
13 votes
2 answers
6k views

Calculate the area of rectangles union

I've been given the following task: Given N rectangles with edges parallel to axis, calculate the area of the union of all rectangles. The input and output are files specified in program arguments. ...
Mikhail's user avatar
  • 229
11 votes
3 answers
2k views

Algorithm to calculate semi perfect integers, lack of efficiency

I'm working on an algorithm to calculate weird numbers, and to do so there are several properties that needs to be calculated, one of them being, if it is NOT a semi-perfect/pseudoperfect number. My ...
Linus's user avatar
  • 917
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 ...
david's user avatar
  • 1,947
11 votes
1 answer
2k views

Backpropagating with Neural Network

I wrote a Java program implementing a neural network with backpropagation. For anyone who isn't familiar with Neural Networks and Backpropagation, here is a good resource. Here is another ...
jonbon's user avatar
  • 211
10 votes
4 answers
2k views

Sieve of Eratosthenes optimization

I am making a program to find primes between the given range of numbers. Unfortunately, the algorithm I created is too slow. Do you have any ideas of how to optimize the code? ...
Simon's user avatar
  • 245
10 votes
1 answer
2k views

Matrix multiplication

Below is the code that I've written for matrix multiplication: ...
Gokul Nath KP's user avatar
10 votes
2 answers
1k views

Unique value finder

For our first assignment in our algorithm class we are suppose to solve several different questions using information from a 2D array. We are also suppose to optimize our code to get more marks on our ...
Manny's user avatar
  • 101
9 votes
5 answers
16k views

Finding the smallest number whose digits sum to N

I tried my hand at a grade XII Board exam program: Given two positive numbers M and N, such that M is between 100 and 10000 and N is less than 100, find the smallest integer that is greater than M ...
Mission Coding's user avatar
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 ...
ccot's user avatar
  • 341
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 ...
Nishant's user avatar
  • 477

15 30 50 per page
1
2 3 4 5
16