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 ...
ccot's user avatar
  • 341
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 ...
ccot's user avatar
  • 341
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 ...
ccot's user avatar
  • 341
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
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: ...
coderodde's user avatar
  • 28.9k
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 ...
Cristian's user avatar
  • 161
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 ...
coderodde's user avatar
  • 28.9k
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 ...
Mr. Polywhirl's user avatar
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 ...
Will Berner's user avatar
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....
Adil's user avatar
  • 101
1 vote
2 answers
626 views

Leetcode kth largest element without using heaps

I was working on kth largest element problem on leetcode Question Given an integer array nums and an integer k, return the kth largest element in the array. Note that it is the kth largest element in ...
D_S_X's user avatar
  • 189
1 vote
1 answer
90 views

return the number of times is state of bulb changed?

Today in an exam I faced a problem which is Toggled Switches(Hacker Earth) as it is an exam question So, I am unable to send the question or its link (exactly). Problem: we have to print a number ...
chandu_reddim's user avatar
2 votes
1 answer
62 views

Distribute items based on the time duration

I just finished a small assignment and I would like to get some feedback about the implementation here. Basically, it was all about distributing items ("talks" in this case) throughout the ...
user avatar
3 votes
1 answer
268 views

LeetCode 146: LRU Cache III

I'm posting my Java code for LeetCode's LRU Cache. If you have time and would like to review, please do so. Thank you! Problem Design and implement a data structure for Least Recently Used (LRU) ...
Emma's user avatar
  • 3,527
2 votes
0 answers
801 views

LeetCode 218: The Skyline Problem II

Here I'm posting my Java code for the skyline problem. If you have time and would like to review, please do so, I'd appreciate that. Problem A city's skyline is the outer contour of the silhouette ...
Emma's user avatar
  • 3,527
3 votes
1 answer
468 views

LeetCode 767: Reorganize String

Here I'm posting my code for the Reorganize String problem on LeetCode. If you have time and would like to review, please do so, I'd appreciate that. On LeetCode, we are only allowed to change the ...
Emma's user avatar
  • 3,527
0 votes
1 answer
174 views

LeetCode 76: Minimum Window Substring - Java

I'm posting my Java code for the Minimum Window Substring. If you have time and would like to review, please do so, I appreciate that. Problem Given a string string...
Emma's user avatar
  • 3,527
5 votes
2 answers
480 views

How to optimize Karatsuba algorithm (using arraylist and java)

I was using Karatsuba algorithm to multiply two polynomials and return the coefficients and I am using java, we are asked to use arraylists here, however, my code is too complicated and it takes much ...
Jenny's user avatar
  • 51
1 vote
2 answers
477 views

How to efficiently find if numbers in a given range contains either 1 or 3, but not both?

I am having a trouble speeding up my implementation. The question is, given a range of numbers from long a to long b, find how many lucky numbers are between a and b inclusive. A number is a lucky ...
Juhyeon Lee's user avatar
5 votes
2 answers
104 views

Performance Enhancement of A Star Path Finder algorithm with 1024 multidimentional array

I have the below code for a A* pathfinder, however it is taking upwards of 10 minutes to find a solution using a simple 1024 x 1024 array. I had to comment out ...
Ian Taylor's user avatar
0 votes
2 answers
612 views

Java Palindrome - Time & Space Complexity

Which of these three methods is the most efficient? Also, what is the time & space complexity of each? ...
PacificNW_Lover's user avatar
4 votes
2 answers
86 views

Filtering product ids

As regarding the following question I have completed the code as below. But I am curious about other effective solutions. I am also curious about if there is any solution that could be applicable by ...
Neslihan Bozer's user avatar
1 vote
1 answer
181 views

"Edit Distance" algorithm

I have a piece of code that calculates the edit distance between words and works, but it's apparently not fast enough. ClosestWords.java: ...
Schytheron's user avatar
4 votes
5 answers
1k views

Counting number of `1` digits in the value of \$11^n\$

I am trying to improve the efficiency of my code, The Question is: Given a value n, where n is in the range ...
Prash's user avatar
  • 41
2 votes
2 answers
195 views

Brute-force ID reversal search

EDIT The random number generator in this code is a blackbox for a similar algorithm that isn't publishable for privacy concern. The algorithm works in similar way, in that it takes in a seed value ...
Hither Joe's user avatar
3 votes
1 answer
252 views

Knuth-Morris-Pratt algorithm in Java Finding substrings in a matrix

Problem Given two matrices: a pattern p and a text t. Write a program that counts the number of occurrences of ...
a-ina's user avatar
  • 305
6 votes
1 answer
430 views

Remove elements compared with other elements in a Set based on a condition

Simplified the actual problem to focus on comparing/removing performance. Given a set S with n elements , find the most optimal way to compare each element to all others until a condition is met that ...
Arjen's user avatar
  • 63
1 vote
1 answer
448 views

Adding a number to an array of digits

I'm a student in my first semester and in my free time and holidays, I do some java training to keep my mind from rusting...so I downloaded this amazing Digital Algorithms practice app and came across ...
StudentAccount4's user avatar
1 vote
0 answers
256 views

Algorithm X implementation for Minimum Dominating Set

As as final project for a MOOC I wanted to write a program that finds the exact cover set/minimum dominating set from the given social network data. So I did end up with writing this. I kinda followed ...
alemst11's user avatar
7 votes
2 answers
2k views

Arranging numbers in a circle such that the sums of neighbors and sums of diametric opposites are prime

I need to create a circle with numbers from 1 to n , however it is necessary to respect some rules: All numbers from 1 to n are used in the circle only once. The sum of two consecutive numbers ...
Gabriel's user avatar
  • 391

15 30 50 per page
1
2 3 4 5
8