Questions tagged [algorithm]

An algorithm is a sequence of well-defined steps that define an abstract solution to a problem. Use this tag when your issue is related to algorithm design.

Filter by
Sorted by
Tagged with
0 votes
0 answers
50 views

Is this iterative inorder traversal algorithm well-known?

I was concerned about the approach in Morris traversal algorithm and came up with simpler solution that uses parent pointers in nodes. The constraints were following: Time Complexity: O(n) Space ...
Max's user avatar
  • 1
0 votes
1 answer
74 views

Move timestamp to the next Monday 10:01 AM

I've been battling ChatGPT for hours now and can't get satisfied with this simple algorithm in TypeScript. These two (hopefully correct) TypeScript+ReactNative solutions should move the timestamp ...
Slazer's user avatar
  • 101
7 votes
2 answers
2k views

Gaussian elimination algorithm in C++

Given: j-g-h-i=0 a+b-c-j=0 c+i-d-e=0 e+g-f=0 And known: a=10 b=7 d=3 e=2 f=3 j=14 I want to solve this (or similar equations) ...
Tobias Grothe's user avatar
3 votes
1 answer
88 views

Pentomino solver in Python

When I was a child, I used to play Ubongo board game, recently I discovered Pentomino puzzle and I wanted to create a custom solver in python for it. Here is what I got: ...
Riomare's user avatar
  • 31
0 votes
1 answer
64 views

HackerRank Algorithm Problem: Climbing the Leaderboard (Python)

Here is the Hackerrank problem which is related to dense ranking and below is my solution which didn't pass the time limit cases. Any better way to optimize this? ...
peternish's user avatar
2 votes
1 answer
46 views

Creating Worst-Case Scenario for QuickSort using Middle Pivot in Java

I've implemented a solution to generate the worst-case scenario for QuickSort using the middle pivot strategy in Java. The goal is to rearrange an input array to produce the worst performance during ...
Lydia Yuan's user avatar
0 votes
3 answers
68 views

another Merge Sort

I've tried to implement merge sort in c with varying degrees of success, one was correctly sorting the array but leaking memory, one was neither sorting the array and leaking memory. The following was ...
Voiceroy's user avatar
  • 103
1 vote
3 answers
94 views

Another ATMs cash-out (denomination) algorithm in Java

Related to this question and this answer, I would like to have a second review from you on a modified version. The problem I tried to solve Some kind of "Minimum count of numbers required from ...
Tobias Grothe's user avatar
2 votes
2 answers
294 views

Another cash machine with special bill values in Java

Task: An ATM dispenses banknotes with the following values/denominations: {5, 30, 35, 40, 150, 200}. The user should be able to repeatedly enter an amount divisible by 5 without leaving a remainder. ...
Tobias Grothe's user avatar
0 votes
0 answers
16 views

Login panel .feature (gherkin) file

I think many days ago, I randomly got introduced to cucumber developement, And it seemed like a conventional and interesting principle of software development. At this very time, I'm concentrating on ...
KhodeNima's user avatar
  • 167
0 votes
0 answers
17 views

Object-based Radix Sort via an Iteratee

I recently finished implementing a radix sort for objects where either one of the keys is numeric, or can be expressed numerically via an iteratee. ...
Christopher Fimbel's user avatar
4 votes
0 answers
123 views

Find the longest "common sequence" in two lists

In short, the algorithm must find the longest sequence that joins together common sequences from two lists (a more formal specification is given in the code's header). The lists are assumed to contain ...
user266319's user avatar
4 votes
1 answer
1k views

Determine if it is EU summer time in Java

I wanted to write a utility method for learning purposes to determine if a given date (year, month and day) falls within EU summer time or not, without using any of the Java library methods. Is here ...
Tobias Grothe's user avatar
1 vote
2 answers
122 views

Ackermann function iterative-recursive form in C

I am trying to write the Ackermann function iterative in m and recursive in n. I got to this point where the code I provided below work for all values below Ack(5,0) but it overflows after this value. ...
anton's user avatar
  • 11
3 votes
2 answers
261 views

Reduce time complexity to process sub-arrays

For a given integer array of size n, find all possible sub arrays of size k which range from 1 to n. Now find the common item which is also a minimum in all sub-arrays of size k, if no common item is ...
technotigr's user avatar
2 votes
1 answer
273 views

Traveling Salesman Problem for visiting cities

Implement TSP problem using best first algorithm (so it will be backtracking, branch-and-bound, and best-first). Since you are looking for a cycle, the start/finish city is not important. Therefore we ...
Ruiru's user avatar
  • 21
1 vote
5 answers
246 views

Sum of bitwise XOR of each subarray weighted by length

here is the problem statement You are given an array a of length n consisting of non-negative integers. You have to calculate the value of \$\sum_{l=1}^n \sum_{r=l}^n f(l,r)\cdot (r - l + 1)\$ where \...
Gurnoor Singh's user avatar
2 votes
2 answers
142 views

Checking a mastermind answer as fast as possible

This is not your typical mastermind question, I am not trying to find the right answer. Merely to check the answer and provide a result as fast as possible. The function signature cannot be changed, ...
ice-wind's user avatar
  • 133
2 votes
3 answers
148 views

Bubble Sort as extension to Swift-Arrays

Task description: Implement an extension for Array, which sorts the elements using the Bubble Sort-algorithm. My implementation: ...
michael.zech's user avatar
  • 4,232
2 votes
1 answer
133 views

Find character at given index in a sorted sub strings [closed]

For a given string say dbac the possible substrings are [d,db,dba,dbac,b,ba,bac,a,ac,c]. Sort them and concatenate to a string: ...
technotigr's user avatar
2 votes
2 answers
59 views

Calculating the sum of all k-sized sub-arrays in an array using sliding window algorithm

I need to calculate the sum of all k-sized sub-arrays in an array using sliding window algorithm. Is that a valid sliding window algorithm? If not, why? ...
Alekam's user avatar
  • 21
0 votes
1 answer
219 views

Leetcode: 2327. Number of People Aware of a Secret

On day 1, one person discovers a secret. You are given an integer delay, which means that each person will share the secret with a new person every day, starting from delay days after discovering the ...
jason's user avatar
  • 1
0 votes
1 answer
43 views

Aggregate transactions in slips

I wrote code to aggregate transactions in slips. I'm concerned with the performance of my code because it uses 3 loops that are nested so the time complexity will be cubic. This code won't scale well ...
bit's user avatar
  • 143
2 votes
1 answer
65 views

Finding the kth smallest number where all (hexadecimal) digits are different

I'm mostly trying to understand why the simpler char array mask below (to track which digits have been already used) is much ...
Shihab Shahriar Khan's user avatar
2 votes
2 answers
131 views

Counting duplicate elements in two sorted arrays

I've been working on an assignment that involves optimizing a duplicate finding algorithm for sorted arrays, and I'd like to get your thoughts on the implementation. Here's the code I've come up with: ...
Bryan C's user avatar
  • 21
4 votes
2 answers
535 views

O(nlogn) Lexicographically minimal rotation code but tle on this particular case

Based on a small suggestion here , this code tries to find lexicographically minimal rotation (question) by successively comparing two adjacent substrings in the very left , that can potentially give ...
Aryaman 's user avatar
1 vote
2 answers
165 views

Two sum sliding window challenge

The task is a simple coding challenge I took part in. It is a spin on the two sum problem. In the two sum problem you are given an validation sequence A and a test input I. I is valid if it's the sum ...
PrancingCrabulon's user avatar
2 votes
1 answer
83 views

Non-recursive topological ordering, starting from given nodes, for Guava graphs

This method returns the topological ordering of a Guava graph starting from a given set of nodes. It's from my personal project github.com/jbduncan/guava-graph-utils, where I'm exploring utilities for ...
jbduncan's user avatar
  • 141
4 votes
2 answers
79 views

C++ Neuron Spike Raster Deserializer

Please help me establish a solid foundation for this computational neuroscience project. I'd like to make sure I'm moving forward with something reasonable before I begin tackling the more complex ...
Ders's user avatar
  • 43
2 votes
1 answer
124 views

Swift-function for finding missing Integers in an array of sequential Integers

Task description: Implement a function, which receives an array of unsorted numbers from 1 to 100. In the array zero or more numbers might be missing. The function shall return an array containing the ...
michael.zech's user avatar
  • 4,232
9 votes
3 answers
2k views

Optimizing the Egg Drop Problem implemented with Python

I've implemented the Egg Drop Problem using Python. As described in the code, I'm trying to find the highest floor of a 102-story building from which I could drop an egg without it breaking. The ...
Muhammed Abiola's user avatar
1 vote
1 answer
64 views

Increment sequence value for multiple styles

I've found several examples of code to increment various sequence values but they are usually specific to either alpha characters or numeric characters. I wanted something that could increment a ...
G_Hosa_Phat's user avatar
0 votes
0 answers
69 views

Tried to come up with a novel sorting algorithm on my own

As said in the title, I tried to come up with a sorting algorithm on my own to practice. It seems to work, even though it's not in place. Is it "new" or does it already exist? ...
Lorenzo Salmonese's user avatar
8 votes
3 answers
2k views

Sieve of Eratosthenes in C++ with wheel factorization

I have written a completely working C++ program for the first time, and I have managed to compile it. I have decided to learn C++ and I have written a C++ program to familiarize myself with C++, this ...
Ξένη Γήινος's user avatar
3 votes
1 answer
321 views

Python function to find the count of digits of numerals in base n up to a given limit

This is a simple exercise to find the count of digits of all numerals in a given base up to a given limit (not including the limit), I wrote it to determine the ratio of bytes saved when the numbers ...
Ξένη Γήινος's user avatar
9 votes
3 answers
2k views

Repeatedly remove a substring quickly

I'm trying to solve the USACO problem Censoring (Bronze), which was the first problem for the 2015 February contest. My solution works for some test cases, but then times out for test cases 7-15. I ...
Kimi M's user avatar
  • 101
0 votes
2 answers
168 views

Python script that makes generalized Ulam spirals

This is a Python script I wrote to generate generalized Ulam spirals. I call the spirals generated by my code Ulamish spirals, they are one dimensional polylines that cross all two dimensional lattice ...
Ξένη Γήινος's user avatar
-2 votes
1 answer
137 views

Design an algorithm to predict words based on a skeleton from a given dictionary

The model I'm building first selects a secret word at random from a list. The model which uses an API then returns a row of underscores (space separated)—one for each letter in the secret word—and ...
driver's user avatar
  • 212
1 vote
3 answers
96 views

Print last lines of file

Task Write a Ruby function, which accepts a path to a text file and returns a string consisting of the last n lines in reversed order, separated by commas. Example input file: ...
michael.zech's user avatar
  • 4,232
5 votes
3 answers
518 views

Python script to split overlapping ranges, version 4

This is the fourth iteration of a Python script I wrote that splits overlapping ranges, and this is the fastest version I have wrote so far, and also a version that works for all inputs. I have done ...
Ξένη Γήινος's user avatar
1 vote
1 answer
106 views

Implement the Swift pow(base, exp)-function yourself

Task: Implement a function, which accepts two integers and results the first number raised to the power of the second number. Both numbers have to be positive. Examples: The arguments 4 and 3 shall ...
michael.zech's user avatar
  • 4,232
1 vote
0 answers
60 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
  • 27k
1 vote
3 answers
107 views

Ruby FizzBuzz using the ternary operator two times

Task: Implement a function which loops from 1 to 100 and prints "Fizz" if the counter is divisible by 3. Prints "Buzz" if the counter is divisible by 5 and "FizzBuzz", ...
michael.zech's user avatar
  • 4,232
0 votes
1 answer
69 views

Changes hash to allocate values as directed

Let's say you have a hashmap of sub-systems that a spaceship is currently directing power to and a second hash of sub-systems where the power should now be directed to. Create a function that returns ...
Nelo's user avatar
  • 125
1 vote
0 answers
79 views

Performant 2D Grid Cluster Finder Algorithm

I would like to vastly improve the speed of the second part of this algorithm to find clusters of points on a 2D grid. Each point is represented by a Region on the ...
ProgrammingTenants's user avatar
3 votes
2 answers
543 views

New York Times' Digits Game Solver

I wrote an algorithm to solve the New York Times' Puzzle: Digits. You could play the game here. The rules of the game are as follow: You were given 6 numbers and you could use simple operations (plus, ...
user274177's user avatar
1 vote
0 answers
93 views

Backtracking graph algorithms for a word puzzle in Python

Motivation Recently, Buzzfeed released a browser-based puzzle game called "Pyramid Scheme." It is available at the following link. The puzzle in an initial state looks like this: To solve ...
WilliamMorris's user avatar
10 votes
2 answers
2k views

A* algorithm implementation in modern C++

I've written the A* search algorithm in C++. My goal is primarily writing concise and understandable code, while making use of some new features of modern C++ (where appropriate) and having generally ...
Green绿色's user avatar
4 votes
2 answers
378 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
71 views

Fantasy football team builder [closed]

I'm very very new to coding. I'm trying to make an app that helps pick fantasy football players. It takes inputs from the user about what their preferences are and outputs a file that gives them a ...
Mally's user avatar
  • 19

1
2 3 4 5
101