All Questions
Tagged with time-limit-exceeded combinatorics
37
questions
0
votes
1
answer
110
views
Effective encoding-decoding chain determination (time optimization)
Could you please help with speeding-up this code?
Input: UTF-8 text (encoded 1-3 times from known pool of encodings). Every time was encoded and decoded by random encoding from pool. Original was koi8-...
7
votes
2
answers
1k
views
Find all combinations of length 3 whose sum is divisible by a given number
I came up with a suitable solution to a HackerRank problem that failed because the execution took longer than 10 seconds on lists that were of very large size.
The problem: Given a list ...
2
votes
2
answers
792
views
Subarrays with length
You are given an array A of length N (where N is as large as 2×105). All elements of the array are positive integers less than or equal to N. Determine the count of subarrays (contiguous subsequences) ...
5
votes
2
answers
2k
views
Find non-overlapping pairs of elements in a list whose difference is less than some given threshold
I have the following task: Let us have a list (denoted by L, and for simplicity, the elements come from the interval [0,1]). We are given a parameter (denoted by C), and we want to find as many pairs ...
2
votes
0
answers
38
views
Loop through the nearest switch and deletion neighbours of a Boolean assignment
My goal is to look for nearest neighbours in a Boolean-assigned mapping (a Python dictionary). For this purpose I'm looping through the candidates, starting from those with the closest distance. The ...
0
votes
2
answers
130
views
0
votes
1
answer
1k
views
Generating permutations fast
I run into a performance bottleneck in a program. I have to generate all permutations for a given sequence with size up to n=11.
My code:
...
2
votes
1
answer
89
views
Count the different positions reached in a cycle of permutations
I have come across a problem on cyclic permutations. It is about swapping numbers around.
It starts out with input N < 100,000 which makes the first N natural numbers as orders: 1 2 3 ... N-1 N
...
2
votes
3
answers
3k
views
Counting numbers that are divisible by 3 and can be produced from the digits of a given number
I'm trying to solve this problem from codewars.
Problem
Given a certain number, how many multiples of three could you obtain with its digits? Suppose that you have the number ...
2
votes
3
answers
146
views
Counting paths between 3 cities in C++
The task is to make a program that prints out how many possible paths a driver can use to visit three cities so that he visits each city exactly n times. The program must be executed within 1 minute ...
2
votes
2
answers
127
views
Forming all multiples of 3 using the given digits
I'm working on this kata from Codewars. The task is:
Given a certain number, how many multiples of three could you obtain with its digits?
Supose that you have the number 362. The numbers that can be ...
0
votes
2
answers
909
views
Lattice path from Project Euler with Python solution
I was trying to solve this problem called lattice path from Project Euler:
Count the number of unique paths to travel from the top left to the bottom right of a lattice of squares.
How many such ...
10
votes
3
answers
709
views
Master Locksmith
Description
Master Locksmith has just finished the work of his life: a combination
lock so big and complex that no one will ever open it without knowing
the right combination. He's done testing ...
3
votes
1
answer
594
views
Bovine Shuffle using a queue (USACO Dec 2017 Silver)
I am working on the "Bovine Shuffle" problem from the December 2017 USA Computing Olympiad, and have got it to work for every test case beside two. When I run these two cases on my own computer, they ...
8
votes
2
answers
1k
views
Python solution to Code Jam's 'Rounding Error'
The "Rounding Error" problem of Round 1B of Google Code Jam 2018 is as follows:
Problem
To finally settle the age-old question of which programming language is the best, you are asking a total ...