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
1
vote
0answers
23 views

Why is my function timing out when run with a larger data set?

I am working on a Code Kata ...
-4
votes
0answers
69 views

Given an array and an integer k, find the count of contiguous elements after k swaps

Given above the question of some codility challenge, I tried solution given below. Given solution passed all the given test cases but not passed performance test. Please help me to know where my ...
0
votes
1answer
35 views

Get average post score of TOP 10 tags on StackOverflow using Stack Exchange Data Explorer

I want to use the Stack exchange data explorer in order to display some basic information about the top tags. The query should print the number of questions and answers, the average number of answers ...
1
vote
0answers
25 views

Wildcard Matching with DFS and FSM

I'm trying to solve Wildcard Matching on Leetcode. I found a great solution using the Finite-state machine. The author builds an FSM and searches with BFS. I rewrite the solution with the same idea (...
3
votes
2answers
162 views

Finding median of sub arrays taking too much time

I'm trying to solve a programming challenge where I have to find the median of given subarrays of an array. I have used std::vector's ...
0
votes
1answer
101 views

The Great Julya Calendar

Challenge An integer is provided as an input. In each step, we have to subtract a number from the input which already exists as a digit of the input. In this way, we have to make the input ...
1
vote
0answers
59 views

Best Travel Kata C++

https://www.codewars.com/kata/best-travel Briefly, the problem states that we have to create a function choose_best_sum(int t, int k,std::vector<int> xs) ...
0
votes
1answer
92 views

Codewars: Prime Streaming (PG-13)

I'm timing out on Codewars' Prime Streaming kata. Below is my code: ...
2
votes
0answers
82 views

Given an integer array A and a range, find a subarray within the range with a minimum sum

Problem HackerRank Range query: You are given an array A of n integers. You have to perform ...
2
votes
1answer
157 views

Dynamic Array Problem (Hacker rank)

I am trying to solve the Dynamic Array problem on HackerRank: Create a list, seqList, of N empty sequences, where each sequence is indexed from 0 to N-1. The elements within each of the N ...
2
votes
2answers
76 views

Designing a stack such that getMin() is both constant time and constant space

I'm attempting the SpecialStack problem on GeeksforGeeks. Design a data-structure SpecialStack (using the STL of stack) that supports all the stack operations like push(), pop(), isEmpty(), ...
3
votes
1answer
40 views

Flash Memory block write counting & thresholding

I am trying to solve this question: In a block storage system, new data is written in blocks. We are going to represent the flash memory as one sequential array. We have a list of block writes ...
-4
votes
1answer
55 views

Geting maximum prime factor for a given number [closed]

I'm trying to solve a problem from Project Euler: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? and here is my attempt: ...
2
votes
1answer
28 views

python segment tree - count of smaller numbers after self

I am trying to solve this question https://leetcode.com/problems/count-of-smaller-numbers-after-self/ You are given an integer array nums and you have to return a new counts array. The counts ...
2
votes
2answers
82 views

Find all pairs of numbers such that the number of binary 1's in their OR is maximum

So, I tried to solve this question and my code did not execute within time-limits. https://www.hackerrank.com/challenges/acm-icpc-team Here's my code, ...
2
votes
1answer
66 views

Python Fenwick Tree

I am trying to solve this question: https://open.kattis.com/problems/fenwick A Fenwick Tree (also known as a Binary Indexed Tree) is a data structure on an array which enables fast (𝑂(log𝑛)) ...
3
votes
1answer
111 views

Find positive integer with a minimum number of binary 1's such that its bitwise AND with all array elements is not 0

Task You have an array of positive integers. Your task is to find an integer x such that the following are true: Bitwise AND between ...
5
votes
2answers
141 views

Frequency Queries (Hackerrank)

This is the problem: You are given queries. Each query is of the form two integers described below: 1 x: Insert x in your data structure. 2 y: Delete one occurrence of y from your data ...
2
votes
1answer
80 views

Permutation 1…N. Answer queries “How many numbers between [X,Y] position are in the interval [L,K]”?

So I am solving this task: We have an permutation of the numbers 1..n. I need to answer m queries: -How many numbers between X-th and Y-th position are in the interval [L,K] (<=k and >= L)? So my ...
6
votes
1answer
129 views

City Construction Solution times out for large input

Problem The country of Hackerland has n cities connected by m uni-directional roads. The cities are numbered from ...
7
votes
3answers
247 views
2
votes
1answer
114 views

Maximum sum combination

I am trying to solve this question: https://www.codechef.com/problems/TADELIVE Andy and Bob are the only two delivery men of Pizza-chef store. Today, the store received N orders. It's known that ...
2
votes
2answers
120 views

ICMP ping all hosts in a range

I'm creating my own little toolbox for pinging IP interfaces (for the test, only in localhost). In the future I'm thinking of piping the output to a text file. But I'd like to focus on improving the ...
3
votes
1answer
114 views

Minimum window substring – LeetCode

Below is my code for the “Minimum Window Substring” LeetCode problem in Swift: Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity ...
6
votes
1answer
107 views

Count swaps needed to order a list of integers

I wrote this code since I'm going through the hackerrank challenges, however, it takes way too long to run. Its function is described on the title, but just to clear it up, we need to count the ...
1
vote
2answers
259 views

HackerRank Problem - “Queen's attack II”

I am new to python and coding in general and I recently found HackerRank. I have been mostly doing easy problems until now. Today, I saw the problem "Queen's Attack II" (https://www.hackerrank.com/...
4
votes
0answers
68 views

Extracting cycles from directed graph with max degree 1 and then performing set cover on cycles

I'm trying to solve P1243E in an efficient manner. The problem in simple words is: Given \$k\$ boxes, \$i\$-th box with \$n_i\$ numbers. All numbers are distinct. We need to select one number from ...
4
votes
2answers
179 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
128 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
71 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
111 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
88 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
130 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 ...
2
votes
1answer
128 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
302 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
211 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
74 views

Python Bubble sort

...
5
votes
1answer
283 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
308 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
102 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
207 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
93 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
238 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
589 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
199 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
81 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 ...
3
votes
1answer
109 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
132 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
219 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 ...

1
2 3 4 5
18