# Latest Questions tagged Algorithm

Browse all latest questions tagged Algorithm

47
Published 19 Sep, 2022
##### Java - Kotlin: java.lang.UnsupportedOperationException in MutableList add element

I'm implementing a stack algorithm for study purpose in Kotlin class Stack&lt;T:Comparable&lt;T&gt;&gt;(list:MutableList&lt;T&gt;) { var items: MutableList&lt;T&gt; = list fun isEmpty():B...

92
Published 07 Sep, 2022
##### Java - detect last foreach loop iteration

Supposing that I have some foreach loop like this: Set&lt;String&gt; names = new HashSet&lt;&gt;(); //some code for (String name: names) { //some code } Is there a way to check inside foreach...

58
Published 25 Aug, 2022
##### Python - Solving a cubic equation

As part of a program I'm writing, I need to solve a cubic equation exactly (rather than using a numerical root finder): a*x**3 + b*x**2 + c*x + d = 0. I'm trying to use the equations from here. How...

21
Published 23 Apr, 2022
##### Javascript - Implementation of Luhn algorithm

I am trying to implement simple validation of credit card numbers. I read about the Luhn algorithm on Wikipedia: Counting from the check digit, which is the rightmost, and moving left, double the va...

87
Published 24 Aug, 2022
##### Python - Hungarian algorithm: multiple jobs per worker

Is there an extension of the Hungarian algorithm that caters for the assignment of multiple jobs per worker? In its simplest form, the algorithm assigns a single job to a single worker. My applicati...

15
Published 01 May, 2022
##### Python - How can I check Hamming Weight without converting to binary?

How can I get the number of "1"s in the binary representation of a number without actually converting and counting ? e.g. def number_of_ones(n): # do something # I want to MAKE this FA...

95
Published 01 Sep, 2022
##### Java - Efficient data structure that checks for existence of String

I am writing a program which will add a growing number or unique strings to a data structure. Once this is done, I later need to constantly check for existence of the string in it. If I were to use...

2
Published 23 Apr, 2022
##### Javascript - Does any change in an array gets to change the entire array?

I got into that question by thinking about sorting algorithms. Does changing an element position inside an array would be the same, at the interpretation, compilation or run-time phases, to recreate...

95
Published 19 Aug, 2022
##### Python - Finding shortest combinations in array/sequence that equals sum

I'm totally stuck and have no idea how to go about solving this. Let's say I've an array arr = [1, 4, 5, 10] and a number n = 8 I need shortest sequence from within arr which equals n. So for...

26
Published 24 Aug, 2022
##### Python - Rock Paper Scissors - get winner mathematically

I just finished my rock paper scissors game in python. Right now, the user has to chose between three buttons, and a string user1 is set to either "Rock", "Paper", or "Scissors". And when I evaluate t...

29
Published 26 Apr, 2022
##### Python - Efficient calculation of Fibonacci series

I'm working on a Project Euler problem: the one about the sum of the even Fibonacci numbers. My code: def Fibonacci(n): if n == 0: return 0 elif n == 1: return 1 else:...

49
Published 19 Aug, 2022
##### Python - Codility Genomic Range Query

I recently discovered Codility and I'm going on with the demo training. I wrote this solution to the Genomic Range Query problem, it works fine, solution is provided with dynamic programming, but it s...

45
Published 29 Jun, 2022
##### Python - Vectorize finding closest value in an array for each element in another array

Input known_array : numpy array; consisting of scalar values only; shape: (m, 1) test_array : numpy array; consisting of scalar values only; shape: (n, 1) Output indices : numpy array; shape: (n,...

83