The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [fastest-algorithm]

Fastest-algorithm competitions are won by the answer with the smallest asymptotic time complexity. For challenges based on actual runtime, use [fastest-code] instead.

Filter by
Sorted by
Tagged with
3
votes
1answer
137 views

Highest cardinality grouping of contiguous integers with minimum-sum threshold

Challenge Given an array of positive integers and a threshold, the algorithm should output a set of consecutive-element-groupings (subarrays) such that each group/subarray has a sum greater than the ...
8
votes
1answer
192 views

Compute my Sacred Geometry [closed]

In the tabletop RPG named Pathfinder, there is a feat that characters can take called Sacred Geometry, which allows a character who has it to buff their spells in exchange for doing some math: to use ...
1
vote
0answers
96 views

Total time to deteriorate all shielded cells [closed]

Problem: We have a two dimensional matrix of positive integer cells. On each turn any non-zero cell with a neighbor (top/bottom/left/right) of zero decreases by 1. We want count to the number of non-...
-6
votes
4answers
189 views

Is this number a palindrome? [closed]

Input A single integer in your language's preferred format. This format is non-negotiable (no input as strings, arrays of digits, etc.), but standard I/O formats do apply if otherwise it would be ...
22
votes
23answers
3k views

Upside-Down Pyramid Addition…REVERSED!

Upside-Down Pyramid Addition is the process of taking a list of numbers and consecutively adding them together until you reach one number. When given the numbers ...
3
votes
0answers
184 views

Minimum cost of solving the Eni-Puzzle

You're tasked with writing an algorithm to efficiently estimate cost of solving an Eni-Puzzle from a scrambled state as follows: You're given m lists of containing n elements each(representing the ...
6
votes
2answers
295 views

Buy the most appropriate items

A store is having a big sale. If your price reaches $199 or more, you can reduce it by $100. You can buy each product only once. Here's an example list of products: (in order to simplify, the names of ...
3
votes
0answers
97 views

determine if the circle is boxed in [closed]

Pretty simple challenge here. Who can make the fastest algorithm (lowest time complexity) to determine whether or not the circle is "boxed in" given the following setup? Input: Your program receives ...
4
votes
1answer
435 views

Meeting splitter

Introduction Large meetings waste working time. Our aim is to split a large meeting into a number of smaller meetings, so the average number topics that a person discusses is minimized but every ...
-4
votes
2answers
234 views

Fastest way to perform the equivalent of an if-statement in x86 assembly

The task is simple: Create an if-statement from scratch in x86 assembly that runs in as few clock-cycles as possible. Must be x86 assembly. Can't use any of the conditional jump/branch instructions (...
2
votes
1answer
285 views

Two Dimensional Waterflow problem [closed]

The one dimensional twitter waterflow problem is this: You are given an array that represents a hill in the sense that the ith entry is the height of the ith location of the hill. When it rains, ...
1
vote
0answers
169 views

3-inverter with two NOT gates [closed]

Introduction I recently came across an oral exam where the candidates were asked to find a logical circuit than can negate 3 inputs A,B,C using only two NOT gates. ...
5
votes
1answer
351 views

Find elements in an array computing a given function value

Problem Description Given: a function \$f(a, b, c, d, e) = \frac{a \times b}c + \frac de\$ an array \$x = [x_1, x_2, x_3, x_4, ..., x_n]\$ of non-distinct integers a target value \$k\$ What is the ...
2
votes
2answers
400 views

Which number is bigger?

Define f(a,b) := a if b=1; a^f(a,b-1) if b>1 (Tetration, where ^ means power) for positive integers ...
-1
votes
1answer
211 views

Find the longest uninterrupted arc in N dimensions

See similar question for 2D case: Find the longest uninterrupted arc The challenge here is to find the longest uninterruped great circle arc around a unit hypersphere in N dimensions, with a random ...
5
votes
3answers
345 views

Find the longest uninterrupted arc

The challenge here is to find the longest uninterruped arc around a unit circle with a random amount of points distributed in random positions around it. Here is a diagram to assist my explanation: ...
-1
votes
3answers
319 views

Fastest to find the joint

The input is an array (or space-separated string, as you wish), zero-indexed, consisting of one strictly increasing array and one strictly decreasing array (in this order, not other vice versa), each ...
13
votes
3answers
400 views

Remove entries from array to sort it and maximize sum of elements

This challenge is from an admission test to a closed number cyber security course. Anyway it doesn't have to do with cyber security, it's just to test the students logical and coding skills. Task ...
9
votes
3answers
849 views

Approximate floating point number with n-digit precision

We have a floating point number r between 0 and 1, and an integer p. Find the fraction of integers with the smallest ...
3
votes
1answer
1k views

remove duplicates from array [closed]

You have given an array from which we need to remove duplicates. Rules: First or immediate duplicates gets removed first. Array contains natural numbers ...
6
votes
2answers
132 views

Find the rectangle [closed]

Overview Given a 2 dimensional array of values with a filled in rectangle, find the position and size of the rectangle. Do it in the fewest array accesses as possible. Requirements The ...
8
votes
0answers
379 views

Total Derangement (Difficulty Level: Hard)

The problem: Write a function which, given a cycle length n and a number of cycles m, where 'm' is within ...
5
votes
0answers
244 views

Solve a Single Player Tron Game [closed]

Solve a Tron Game Tron is a great game, and if you haven't played it the internet has MANY online versions available. A fun challenge is to try to write an AI that plays Tron, which is normally much ...
1
vote
1answer
114 views

Sequence avoiding near collision [closed]

Task Find a sequence of all numbers between min and max where every number differs from every other number in the sequence by at least "d" digits. Example of sub-sequence For min = 0, max = 1000 ...
1
vote
0answers
109 views

Quotient in base 31 numeral system [closed]

You're given two numbers a and b in base 31 numeral system and number k with no more than 10000 decimal digits. It is known that b is divisor of a. The task is to find last k 31-based-digits of ...
9
votes
7answers
1k views

Digital River (Shortest And Fastest Solution)

This is my first question, so I hope it goes well. Background: It's not the rivers that you might be thinking about. The question revolves around the concept of digital rivers. A digital river is a ...
-2
votes
1answer
2k views

Find the digit occurring the most in a range of prime numbers

Find the digit which occurs the most in a range of prime numbers. Input: Two numbers, p and q, specifying the range; the range ...
2
votes
0answers
185 views

Num of pyramids possible with given number of bricks [closed]

I encountered this question in an interview and could not figure it out. I believe it has a dynamic programming solution but it eludes me. Given a number of bricks, output the total number of 2d ...
-10
votes
1answer
655 views

Hard Puzzle Game Solver [closed]

There is an app called Hard Puzzle which is a game where there is a red circle, and you have to fill all of the surface area with five smaller white circles it may seen easy, but it's harder than it ...
9
votes
7answers
827 views

Heaviest increasing subsequence

A subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. A strictly increasing subsequence is a subsequence ...
2
votes
0answers
221 views

Add or subtract numbers to find the smallest non-negative integer [closed]

Given a positive integer, n, along with n non-negative integers, write a program or function that prints or returns the smallest ...
9
votes
1answer
225 views

Number of unique outputs by substituting variables

Given a set of formulas like this: bacb bcab cbba abbc Give an algorithm that finds the number of unique results you can get when each variable is substituted ...
7
votes
1answer
179 views

Determine sets of associatively equivalent permutations of commutative operations

There are many types of binary operations, which can be categorized by their associative properties and their commutative properties. A binary operation () is ...
12
votes
2answers
1k views

Fastest way to compute order of magnitude in x86 assembly

The task is simple: write assembly that computes the order of magnitude of an integer using as few clock cycles as possible. Order of magnitude is defined as log10,...
0
votes
0answers
200 views

Find the longest recurring substring [duplicate]

Given a string of no more than 255 characters, find a function that returns the longest recurring substring. An example would be: aabbacadeauaaabba where the longest recurring sub-string is aabba. ...
-2
votes
2answers
897 views

Find Anagrams in the Dictionary [closed]

This a code challenge. The winner will be the person to provide the most efficient implementation of the solution in terms of algorithmic complexity. Using the dictionary found in '/usr/share/dict' (...
9
votes
2answers
1k views

A fastest algorithm optimization challenge

This is my first experiment with an asymptotic complexity challenge although I am happy with answers entirely in code as long as they come with an explanation of their time complexity. I have the ...
5
votes
6answers
5k views

Determine the move in which a LOGO turtle crosses a point that it has already visited [closed]

Situation: A turtle starts at (0, 0) on a cartesian graph. We have a non-empty zero-indexed "moves" list that contains numbers. Each number represents the distance moved. The first number is the ...
6
votes
9answers
6k views

Same word when missing letters [closed]

Idea From a given word dictionary (containing only plain letters, i.e: no accent or other special chars), with a given fixed word length, find every same when a given number letters are missing. For ...
5
votes
5answers
854 views

Mr. Moneybag's Money Piles

Mr. Moneybags is a very rich man. He has an assistant Mr. Perfect, who one day, got very mad, and shredded some of Mr. Moneybag’s $100 bills! Mr. Moneybags decided to punish Mr. Perfect. Mr. ...
2
votes
1answer
674 views

Racketeer Taxi Driver

The Scenario You are a taxi driver in your city. You picked up a passenger from the airport and he told you the place he'd like to go. To earn more money, you need to drive as much as you can. ...
5
votes
3answers
261 views

Autoscale complex function

Context: We are working on a complex image drawing program to produce mugs, t-shirts, and so on. Here is an example of such function However, we are facing the following problem: Random generated ...
6
votes
7answers
3k views

Count the Zeros

For a given n, count the total number of zeros in the decimal representation of the positive integers less than or equal to n. For instance, there are 11 zeros in the decimal representations of the ...
15
votes
16answers
30k views

Array Merge without Duplicates

I recently saw this Javascript code on StackOverflow for merging two arrays, and removing duplicates: ...
9
votes
7answers
2k views

Count the number of cyclic words in an input

Cyclic Words Problem Statement We can think of a cyclic word as a word written in a circle. To represent a cyclic word, we choose an arbitrary starting position and read the characters in ...
1
vote
4answers
706 views

Tricky Median Question

Given n points, choose a point in the given list such that the sum of distances to this point is minimum ,compared to all others. Distance is measured in the following manner. For a point (x,y) all ...
8
votes
6answers
2k views

Code-Challenge:The Nearest Prime

Challenge In this task you would be given an integer N you have to output the nearest prime to the integer. If the number is prime itself output the number. The input N is given in a single ...
5
votes
4answers
668 views

Fastest algorithm for decomposing a perfect power

A perfect power is a positive integer that's equal to one positive integer, to the power of another positive integer (e.g. ab is a perfect power). Note that trivial solutions (e.g. b=1) are excluded; ...
16
votes
6answers
6k views

Count number of hefty decimals between 2 numbers

Let's say we have a non-negative integer that is "hefty" (that is, "heavy") if its average digit value is greater than 7. The number 6959 is "hefty" because: (6 + 9 + 5 + 9) / 4 = 7.5 The number ...
13
votes
5answers
5k views

Free a Binary Tree

So before you read some basic computer science concepts. A binary tree is a dynamically allocated structure (usually used for ordered storage). Because of its nature traversal of binary trees is ...