We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [time-limit-exceeded]

When the code scales so poorly in the face of large inputs that it cannot complete in a reasonable amount of time, use this instead of the [performance] tag.

Filter by
Sorted by
Tagged with
4
votes
2answers
152 views

two-sum algorithm

Can someone help me in optimizing the code here? This is the original question Given an array of integers, return indices of the two numbers such that they add up to a specific target. ...
3
votes
2answers
116 views

Determine the length of the largest contiguous segment

Problem Link- https://www.hackerearth.com/challenges/competitive/october-circuits-19/algorithm/ap-1-f43562f4/ Problem Statement : You are given an integer array of size A. You are also ...
0
votes
0answers
68 views

Leetcode Word break 2

I am trying to solve this question Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid ...
2
votes
2answers
95 views

Function to take a positive integer and return the next bigger number formed by the same digits

I've written a solution to a Codewars challenge: You have to create a function that takes a positive integer number and returns the next bigger number formed by the same digits: 12 ==> 21; 513 ...
2
votes
2answers
55 views

Color The Fence codeforces - TLE

I am trying to solve this problem: Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger ...
1
vote
0answers
48 views

Algorithm for building a string by appending and cloning substrings [closed]

I have a problem where I need to construct a given string from scratch for a minimum cost by either: Appending a new character for a cost A Appending a substring of my existing string for a cost B ...
0
votes
1answer
69 views

Solution to knapsack problem exceeds time and RAM limits

My goal is to code the knapsack problem algorithm. The problem is that a knapsack has a given weight limit, W. I have a collection of items which have a given ...
1
vote
1answer
57 views

Add a value to each of the array element between two given indices successively

I am trying to solve the HackerRank: Array Manipulation problem using Java. The problem that I am facing is that the program is running for half of the test cases, while for the other half it is ...
4
votes
1answer
79 views

Creating an inverted index from text documents

I am working on an information retrieval project, where I have to process a ~1.5 GB text data and create a Dictionary (words, document frequency) and posting list (document id, term frequency). ...
4
votes
2answers
86 views

Target Sum leetcode

I am trying to solve this problem You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + ...
1
vote
0answers
65 views

Python Bubble sort

...
5
votes
1answer
69 views

Timeout Error in Fraudulent Activity Notification HackerRank

I am solving this problem: Fraudulent Activity Notifications on HackerRank. I am done with my code and is working, but it is inefficient as well for very large inputs. I don't know but after all ...
2
votes
3answers
307 views

Perform a predetermined set of operations on a large sequence

This is a programming challenge. I have been given the following input: \$n\$ where n is size of sequence \$k\$ is an integer a sequence \$A_0, A_1, A_2, \ldots A_{n-1}\$ I need to ...
4
votes
1answer
96 views

Expanding the region of interest of an image

I am solving a problem of increasing the ROI of a retinal image using the below algorithm- First, the set of pixels of the exterior border of the ROI is determined, i.e., pixels that are outside ...
6
votes
4answers
199 views

Building a toy from Lego toys

I recently attempted a coding problem, but my solution was not well received during the interview (modified slightly to reduce Google-ability). Suppose a child has several Lego blocks, and wants to ...
1
vote
1answer
84 views

Flatten binary tree to linked list

I'm trying to flatten a binary tree into a linked list. I have a working, correct solution: ...
2
votes
1answer
64 views

CCC '19 S5:Triangle: The Data Structure

This problem is from [CCC2019]: https://dmoj.ca/problem/ccc19s5/ (Canadian Computing Contest 2019) and I have implemented it in C++. I used sequence [A054237]: https://oeis.org/A054237/table to ...
10
votes
5answers
568 views

Minimum perfect squares needed to sum up to a target

I'm trying to solve this problem Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n. I've come up with a solution that ...
0
votes
1answer
70 views

VBA Excel Looping through recordset and storing the data to use later

I have a loop to add Recordset items to a Dictionary so I can do comparisons and retrieve specific data later in the code (not ...
2
votes
1answer
70 views

Find the largest sum of the GCD and LCM of two numbers in a range

The program is supposed to get one number n as input, and output the max value of gcd + lcm of two numbers that range from 1 to n. For example, if n == 3, the answer is 7 because gcd(3,2) == 1 and ...
2
votes
1answer
50 views

Maze path finder using Depth-First Search algorithm

I'm trying to resolve this kata from CodeWars. Kata exercise You are at position [0, 0] in maze NxN and you can only move in one of the four cardinal directions (i.e. North, East, South, West). ...
1
vote
3answers
117 views

Sum the largest five numbers

I'm doing a code-challenge problem: Input The first line consists of an integer T (T ≤ 100) which represents the number of test cases. Each test case consists of ...
4
votes
1answer
92 views

Hacker Rank Climbing The Leaderboard

This has been asked a couple of times but here is my implementation in C++. I have 11/12 solutions completed. The 6th test case which has 200000 intial scores and Alice has even more scores causes my ...
3
votes
3answers
192 views

merge list of strings into one sorted string

So I was tasked the following: Given a list of strings, output a sorted string that consists of all lowercase characters (a-z) from each string in the list. Example [aba, xz] -> ...
7
votes
1answer
72 views

Find neighboring PINs on a numeric keypad

I am new to coding and to apply for an internship I need to solve several tasks. This is one of them. I wrote working code, but the program says it takes too long to complete. Help me speed up my code ...
1
vote
1answer
93 views

Check if is it possible to get to a point that is presented by a number [closed]

Problem description from an Iranian online course, translated with the help of Google Translate: Tired of coding, Mehdi has gone on to his childhood games. But because he doesn't know who to play ...
8
votes
3answers
259 views

Find the smallest positive integer that is absent from a given array

I made the acquaintance of big-O a couple of weeks ago and am trying to get to grips with it, but although there's a lot of material out there about calculating time complexity, I can't seem to find ...
2
votes
3answers
109 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
1answer
79 views

USACO Arithmetic Progressions

The problem I'm solving is: given a length of an arithmetic progression, and a limit to the terms (see below), find all progressions that work. All terms of the progressions must be of the ...
7
votes
3answers
583 views

Counting the triangles that can be formed from segments of given lengths

Problem Statement: Given an unsorted array of positive integers. Find the number of triangles that can be formed with three different array elements as lengths of three sides of triangles. ...
6
votes
1answer
149 views

Immediate Smaller Element Time Limit Exceeded

Immediate Smaller Element The code is working fine Code is here. For each element in the array, check whether the right adjacent element (on the next immediate position) of the array is smaller. If ...
4
votes
1answer
93 views

Count words with given prefix using Trie

I have been trying to solve this HackerRank problem: We're going to make our own Contacts application! The application must perform two types of operations: add name, where is a string ...
2
votes
1answer
161 views

How can I make my solution to “Climbing the Leaderboard” not time out?

I tried to solve the following challenge and optimize the solution but my code still times out. My code is below. Problem statement Climbing the Leaderbord Alice is playing an arcade game and ...
19
votes
3answers
4k views

Loading military units into ships optimally, using backtracking

I solved the following problem using backtracking: We are given a list of military units, their weight and their (numerical) strength. We have a number of ships with a limited carrying capacity....
3
votes
1answer
61 views

Daily SQL job to delete records older than 24 hours

Below is a delete job to delete 1M+ records daily and takes 13 hours to complete and sometimes more than that. I need to optimize this. The table tblcalldatastore is being inserted 24*7 through a ...
3
votes
1answer
100 views

CodeChef's Tree MEX (Minimum Excludant) challenge

This code is a solution for CodeChef's Tree MEX problem: Minimum excludant (or MEX for short) of a collection of integers is the smallest non-negative integer not present in the set. You ...
6
votes
1answer
42 views

Search for strings in a list that have > 90% similarity

Explanation: I am working on String comparison in which I want to cross-compare the list of the same input string. For the same string, I am continuing the loop but if a single string will have ...
0
votes
2answers
62 views

Read coordinates from many files and calculate polygon areas

My goal with this snippet is to create an array of coordinates which in turn is a tuple of 68 elements, area and modified area array for all 10k elements and assign it to the ...
0
votes
0answers
512 views

Function to sum values of most significant digit contained

ABOUT For each subsequence, look at its position in the original decimal representation of \$x\$. Let's say that the most significant digit it contained was the \$e\$-th digit, where \$e=0\$ ...
0
votes
1answer
65 views

Optimal BST challenge

I was coding the problem here. I think I have solved it, but I ran into time limit exceeded issues. I am new in Competitive Programming, so I was looking for a better, time efficient logic for solving ...
6
votes
4answers
543 views

Counting multiples of 3 up to a given number

I'm attempting a practice problem in Codeforces that requires you to find the number of multiples of 3 less than or equal to a given number. I have written the following code but it gives a TLE once ...
2
votes
2answers
86 views

Generate a large block diagonal covariance matrix with exponential decay

I am implementing Kalman filtering in R. Part of the problem involves generating a really huge error covariance block-diagonal matrix (dim: 18000 rows x 18000 columns = 324,000,000 entries). We denote ...
2
votes
1answer
56 views

Coding Challenge: Kattis

Short problem description: A sequence of numbers are antiarithemtic if there exists no three numbers a_i, a_j, ...
2
votes
1answer
43 views

Finding the number of times the code will generate an alert depending upon whether the transaction is fraudulent

Please refer to this problem from Hackerrank HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a ...
4
votes
1answer
79 views

Optimising iteration and substitution over large dataset

I have the following code: ...
3
votes
2answers
140 views

Jump Game - Leetcode

Below is my solution for the LeetCode Jump Game Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents ...
1
vote
0answers
53 views

Graph-coloring solution using depth-first search

I'm trying to solve this question: Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorate them. The park consists of n ...
4
votes
2answers
69 views

Finding a vertex of a tree such that every subtree rooted at that vertex is of a uniform color

I'm trying to optimally solve codeforces problem 763A: Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After that they paint all the n its vertices, so ...
5
votes
1answer
83 views

Finding sum of divisors of numbers between the range (1 to 1e16)

The exact link to the question : https://www.spoj.com/problems/DIVSUM2/ Input: An integer stating the number of test cases (equal to 500), and that many lines follow, each containing one integer ...
4
votes
1answer
103 views

Agent based model in Python

My model is based on the Ultimatum Game. I won't go into the intuition behind it but generally speaking it functions as follows: The game consists of a n × n lattice on which an agent is placed at ...