Skip to content

Tag: algorithm

Find closest factor to a number, of a number

I am trying to automate the finding of the closest factor of a number to another number; Example: Closest factor of 700 to 30 is 28 (30 does not go into 700, but 28 does). An obvious solution is just to get all the factors of 700 and do a simple distance calculation to find the nearest factor to 30,

Why is this called backtracking?

I have read in Wikipedia and have also Googled it, but I cannot figure out what “Backtracking Algorithm” means. I saw this solution from “Cracking the Code Interviews” and wonder why is this a backtracking algorithm? Answer “Backtracking” is a term that occurs in enumeratin…

Efficient solution to codingBat riddle starOut in Java

The problem I am talking about is this Problem statment: Return a version of the given string, where for every star () in the string the star and the chars immediately to its left and right are gone. So “abcd” yields “ad” and “ab**cd” also yields “ad”. starOut(&…

How to generate a CUSIP check digit

CUSIPs are a 9-digit alphanumeric code for uniquely identifying a financial security. https://en.wikipedia.org/wiki/CUSIP They were invented in the 1964, and given the reliability of data transmission in the 60’s, the 9th digit is actually a check digit used to confirm the validity of the first 8 charac…

java codility Frog-River-One

I have been trying to solve a Java exercise on a Codility web page. Below is the link to the mentioned exercise and my solution. https://codility.com/demo/results/demoH5GMV3-PV8 Can anyone tell what can I correct in my code in order to improve the score? Just in case here is the task description: A small frog…

Big O – O(log(n)) code example

Like the Big O notation “O(1)” can describe following code: What code can O(log(n)) describe? Another question: What solutions are there for “Big O problems” (what to do, when getting a lot of data as an input)? Answer Classic example: This will be: 2k = x → Applying log to both sides …

Josephus sequence

Description: There are people standing in a circle waiting to be executed. The counting out begins at some point in the circle and proceeds around the circle in a fixed direction. In each step, a certain number of people are skipped and the next person is executed. The elimination proceeds around the circle (…