All Questions
Tagged with complexity java
144 questions
5
votes
4
answers
538
views
Count number of substrings in less time
Given an input string contains letters from 'a' to 'g'
Count how many substrings are there in the input string such that
frequency of any character inside the substring is not more than the
number of ...
13
votes
5
answers
2k
views
solve n*m matrix processing in less time
I want to solve a problem in less time complexity. Here are the details:
Given an n*m matrix, n rows and m columns. Initially, the matrix is empty filled with 0s.
...
-2
votes
2
answers
105
views
complexity reduction (refacto) [closed]
I'm trying to reduce the complexity of this piece of code following a SonarQube error. I have several similar blocks, and even if I try to extract them into private methods, the Sonar error persists.
...
2
votes
1
answer
75
views
Merge Sort with Minimum Sufficient Variables, Verbosity and better Space Complexity
The majority of merge sort implementations searched online are provided with unnecessary variables and code lines. Here is an attempt to reduce that. However, does passing back the subArray as return ...
-2
votes
1
answer
411
views
Number Plate Generation Program
I wrote a number plate generation program. The program generates number plates for a car registered with a specific Memory Tag and on a specific date.
Number plates use the following format: (2 letter ...
3
votes
1
answer
575
views
Finding the minimum element of a stack of numbers
As part of an online programming challenge, I wrote a program that implements a stack of integers, supporting adding and removing elements, finding the last inserted element, and the minimum element. ...
1
vote
2
answers
321
views
SumList Cracking the coding Interview
Sum of 2 numbers, represented with linked lists, where digits are in backward order or forward order.
Backward order Example
INPUT:(7->1->6) + (5->9->2) = 617+295
OUTPUT: 2->1->9 = ...
0
votes
2
answers
327
views
Optimizing methods with multiple if checks on getter values
I have a method where I fetch user input, check if certain values exist, and based on that build my own custom input object that I would use to search in a database. The code for the search method is ...
1
vote
2
answers
1k
views
URLify a given String - replace spaces with %20
I have written a code to replace all spaces in a String with %20.
...
3
votes
1
answer
134
views
Substring search in Java
I am trying to make an algorithm that will find the index of a given substring (which I have labeled pattern) in a given String (...
2
votes
2
answers
874
views
LeetCode 3Sum Java Solution
I have this Java solution to LeetCode's 3Sum problem.
I would be really grateful if I could get feedback on correctness, scalability, efficiency, coding best practices, and OOP design.
I'm relatively ...
3
votes
1
answer
575
views
Ensuring if an object is Assignable from a class type
I am trying to ensure type in the below method. How to reduce its cognitive complexity to below 15 from the current 27? It looks more readable as it is? Is there a way to break this down to make it ...
4
votes
2
answers
2k
views
Time and Space Complexity of Prime factorization
I have written a function that prints all the prime factors for a given number. Here is my code
...
5
votes
4
answers
581
views
LeetCode: Roman to Integer in Java
I tried solve this easy leetcode challenge in java. Challenge link
Here is my solution
...
1
vote
4
answers
380
views
Given the arrival times of people at a door, resolve their passage times
I was trying to solve the following question:
You are given 2 arrays: one representing the time people arrive at a door and other representing the direction they want to go (in or out) You have to ...