Skip to main content

All Questions

3 votes
1 answer
219 views

Leetcode: Number of Islands - BFS (Queue vs Recursion)

I was playing around with leetcode's Number of Islands. As per the challenge's description: Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the ...
5 votes
1 answer
337 views

Leetcode: Largest Number

I was trying out leetcode's Largest Number. As per the challenge's description: Given a list of non-negative integers nums, arrange them such that they form the largest number and return it. Since ...
4 votes
2 answers
496 views

Leetcode: Steps to Make Array Non-decreasing

I was trying out leetcode's Steps to Make Array Non-decreasing As per the challenge's description: You are given a 0-indexed integer array nums. In one step, remove all elements nums[i] where nums[i ...
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 ...
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 ...
2 votes
1 answer
737 views

Traverse a list of tree nodes

I am wondering if there is a better way to traverse a list of trees. Here is my current algorithm: Collect the parent IDs in a Map Traverse all the groups and find ones where their ID is not in the ...
2 votes
2 answers
338 views

Finding all the prime factors of a number

I want to calculate all the prime factors of a number in the range 2 ≤ N ≤ 107. Here is my function: ...
1 vote
0 answers
74 views

A parallel MSD radix sort in Java for integer keys

I have this repository: https://github.com/coderodde/ParallelRadixSort.java/tree/main It contains a parallel MSD radix sort presented below: ...
4 votes
2 answers
663 views

Merge a list of deeply nested HashMaps

Suppose I have a list of hashmaps (<String, Object>). Values can be either scalar types or a nested HashMap with the same type. I need to merge a list of this ...
4 votes
1 answer
2k views

ByteLandian challenge from CodeChef

I am trying to go through the problems on CodeChef and came across this problem: In Byteland they have a very strange monetary system. Each Bytelandian gold coin has an integer number written on ...
1 vote
0 answers
129 views

Making Robert Tarjan's offline LCA algorithm run (much) faster (Java)

I have produced this GitHub repository that compares the performance of: Robert Tarjan's off-line lowest common ancestors algorithm, An improvement of the above algorithm. Typical demo program ...
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 ...
0 votes
3 answers
1k views

Calculate square of (sum of even-indexed) - (sum of odd-indexed) subarrays from an array

Find all subarrays from a given array in the least possible time complexity. Requirement: calculate the square of (sum of even-indexed elements) - (the sum of odd-indexed elements) of al the subarrays....
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 ...
5 votes
4 answers
553 views

Fastest function to find cumulative largest perfect squares of a single number?

I'm attempting to write an algorithm that will find the largest perfect squares of a given integer, subtracting their values from the total each time, as fast as possible. It's somewhat hard to ...

15 30 50 per page
1
2 3 4 5
16