Skip to main content
Share Your Experience: Take the 2024 Developer Survey

New answers tagged

2 votes

Printing longest sequence of zeroes

Optional abuse In the code you shared, Optional is used only to create a chain of method calls and avoid writing conditional ...
Alexander Ivanchenko's user avatar
4 votes
Accepted

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

Performance Figures First of all, regarding these figures in milliseconds. They can be useful, to indicate whether something is wrong with the algorithm, but they can hardly be considered accurate. ...
Alexander Ivanchenko's user avatar
5 votes
Accepted

Optimizing a Function to Check Pronic Numbers in JavaScript

Add guard The function requires a unsigned integer as an argument. A JS number is a floating point double (64bit floating point value). Guard function against bad input by checking is argument ...
Blindman67's user avatar
  • 22.1k
2 votes

Optimizing a Function to Check Pronic Numbers in JavaScript

quadratic complexity how to improve this function's performance The time complexity of these loops is out of control! ...
J_H's user avatar
  • 27.6k
2 votes
Accepted

Optimizing a Function to Generate a Row of Consecutive Odd Numbers in a Triangle

Quadratic, Linear, or Constant This is a linear problem \$O(n)\$ (possibly constant \$O(1)\$ See bottom of answer) however your solution is quadratic \$O(n^2)\$. Note: that the function expects that ...
Blindman67's user avatar
  • 22.1k
3 votes

Optimizing a Function to Generate a Row of Consecutive Odd Numbers in a Triangle

memory consumption it fails to run for large indices I'm guessing due to malloc() fail. The OP computes (roughly) a 2-dimensional matrix: ...
J_H's user avatar
  • 27.6k
4 votes

Leetcode - First Unique Character in a String

Pay attention to Constraints While cracking algorithmic problems, pay very close attention to the constraints of the problem at hand. They can often give valuable clues on how to attack the problem. ...
Alexander Ivanchenko's user avatar
-1 votes

Leetcode 55. Jump Game solution

TC = O(N) SC = O(1) Iterates through the array, updating the maximum reachable index and decrementing the steps available. If it exhausts steps before reaching the end, it returns false; otherwise, it ...
Akhilesh kumar's user avatar
-2 votes

Leetcode - First Unique Character in a String

In Java Use the FirstIndexOf() and LastIndexOf() if these both return the same number then its the unique character in the statring of the string return the index of it break the loop. This is the ...
Ajay Shankar's user avatar
2 votes

Coding challenge for mixing a string

Re: your question about a better way of de-deduplicating, a nice way of de-duplicating frequency entries while also removing the need to do entry cleanup via ...
Setris's user avatar
  • 1,608
7 votes

Advent of code 2023 day 5 in Java: mapping integer ranges to new integer ranges

Use proper types / Avoid abusing Arrays and Collections Put on yourself in the shoes of the code reader and try to answer the question: "What do they make of this type?" ...
Alexander Ivanchenko's user avatar
9 votes
Accepted

Advent of code 2023 day 5 in Java: mapping integer ranges to new integer ranges

Your code needs a complete rewrite. I'll show you some pointers towards the next iteration. import java.io.File; // read file Forget these comments. The reason why ...
TorbenPutkonen's user avatar
4 votes

Coding challenge for mixing a string

nested functions Nested functions aren’t doing you any favors in this case. Place them up at top level, please, where they are accessible to other callers, such as unit tests. doctest Show us example ...
J_H's user avatar
  • 27.6k
2 votes

Coding puzzle - Passing year books

Question: I would suggest to ignore the "fluff" of the pretend real-world example and try to translate the problem into its general terms. I believe, with a small twist, that this question ...
Alex's user avatar
  • 41

Top 50 recent answers are included