Skip to main content

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.

6 votes
8 answers
1k views

Reversing vowels in a string

Given a string s, reverse only all the vowels in the string and return it. The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both lower and upper ...
user avatar
2 votes
1 answer
134 views

Count how many numbers in a range have exactly three divisors

The challenge Given array a of n numbers, I need to count how many positive numbers less than each aᵢ have exactly 3 divisors. Constraints 1 <= aᵢ <= 2.5 * 10¹³ In other words, the minimum ...
Muhammad Usman's user avatar
2 votes
1 answer
185 views

Hackerrank "New Year chaos" solution - permute sequence by swapping adjacent terms

I was doing the Hackerrank "New Year chaos" problem. Here is the description: It is New Year's Day and people are in line for the Wonderland rollercoaster ride. Each person wears a sticker ...
user12138762's user avatar
2 votes
1 answer
69 views

Clique Connect: minimum spanning tree

Problem Statement You are given a weighted undirected graph G with N vertices, numbered 1 to N. Initially, G has no edges. You will perform M operations to add edges to G. The i-th operation (1≤i≤M) ...
user24714692's user avatar
3 votes
1 answer
152 views

Performance Tuning to enable answer for Project Euler #566 "Cake Icing Puzzle"

Related to this question I am still looking for a solution to Project Euler Problem 566 (see link for a nice simulation also): Adam plays the following game with his birthday cake. He cuts a piece ...
DuesserBaest's user avatar
2 votes
1 answer
101 views

Project Euler #566 "Cake Icing Puzzle" Performance Tuning

I am rather new to python and wanted to use Project Euler to learn more about it. The task can be seen here, so I will skip any description of my own: Project Euler Problem 566 (see Link for a nice ...
DuesserBaest's user avatar
6 votes
1 answer
329 views

Codeforces: D2. Counting Is Fun (Hard Version)

The code works okay for the following problem. Problem An array 𝑏 of 𝑚 non-negative integers is said to be good if all the elements of 𝑏 can be made equal to 0 using the following operation some (...
user24714692's user avatar
4 votes
2 answers
497 views

Leetcode: Steps to Make Array Non-decreasing

I was trying out leetcode's Steps to Make Array Non-decreasing As per the challenge's description: You are given a 0-indexed integer array nums. In one step, remove all elements nums[i] where nums[i ...
ccot's user avatar
  • 341
1 vote
3 answers
113 views

Find min sum for indices to match equation

I want to reduce time complexity of my code: I have an array of integers arr say [1, 2, 3, 6, 67] I have an equation : a*x+b*y=z, I can use the array values in this ...
Learner's user avatar
  • 217
9 votes
4 answers
2k views

Leetcode : First Missing Positive

I was trying out leetcode's first missing positive. As per the challenge's description: Given an unsorted integer array nums, return the smallest missing positive integer. You must implement an ...
ccot's user avatar
  • 341
1 vote
3 answers
127 views

Maximum Sum BST in a Binary Tree

I was trying to find the Maximum sum BST of a binary tree on LeetCode. While the Java code I have come up with, mostly seems right and is able to pass 55 out of the given 59 test cases too, the error ...
Siddharth Garg's user avatar
2 votes
1 answer
80 views

Sort array of numbers using tree sort - Leetcode 912

Problem statement: Sort integer array nums in O(N log N) time, without relying on any library sort routine. I am trying to use a tree sort method (using the ...
qxzsilver's user avatar
  • 123
4 votes
2 answers
113 views

Delete a node in binary tree

Problem Statement Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST. Basically, the deletion ...
iskander's user avatar
  • 121
2 votes
3 answers
737 views

Find median value of two Sorted Arrays

To improve my coding knowledge can you please give me suggested changes on my code? ...
Subha Rajagopal's user avatar
2 votes
1 answer
62 views

SEDE query to count questions, views and unanswered for a set of tags

This query selects the number of SO questions, the number of views and the number of unanswered questions for each tag (the list of the tags is the user input). It works fine when it works, but it ...
Yulia V's user avatar
  • 635
1 vote
1 answer
87 views

HackerRank Algorithm Problem: Climbing the Leaderboard (Python)

Here is the Hackerrank problem which is related to dense ranking and below is my solution which didn't pass the time limit cases. Any better way to optimize this? ...
peternish's user avatar
3 votes
2 answers
303 views

Trailing Digits

https://www.acmicpc.net/problem/23204 I've solved a programming challenge where you need to count the occurrences of a specific digit at the end of the product of multiples of a given number within a ...
qleoz12's user avatar
  • 141
0 votes
1 answer
118 views

HackerRank Project Euler 12 (Python) | Highly Divisible Triangular Numbers

I again share my Python code which didn't pass time limit test cases in the HackerRank contest of ProjectEuler. ...
peternish's user avatar
4 votes
1 answer
525 views

calculate the number of ways to pick two different indices

I'm working on a codesignal practice problem You are given an array of integers a and an integer k. Your task is to calculate the number of ways to pick two different indices i < j, such that a[i] ...
Josh's user avatar
  • 41
2 votes
1 answer
108 views

Codeforces: Dasha & Nightmares

so I got started with competitive programming about a day ago and I got stuck on the first random question I tried on codeforces. It's called Dasha and Nightmares. Problem Description: The problem ...
st0n3r's user avatar
  • 73
2 votes
1 answer
745 views

Traveling Salesman Problem for visiting cities

Implement TSP problem using best first algorithm (so it will be backtracking, branch-and-bound, and best-first). Since you are looking for a cycle, the start/finish city is not important. Therefore we ...
Ruiru's user avatar
  • 21
6 votes
1 answer
127 views

One or more planets to line up with the earth a certain amount of times

I have attempted the below question, however my solution is too slow (i.e. It does not fit the 2 second time constrain for java). How can the solution be optimised? While at IOI 2020 in Singapore, ...
Zareef Akoodie's user avatar
1 vote
1 answer
56 views

Find all combinations of two companies grouped by the projects they are tendering for

I am working on the task to get all possible combinations (pairs) of ID's (companies) which participated in one bid and create a new data frame with ID_1, ID_2, matching parameter (tender ID). I have ...
Vasya_Ch's user avatar
2 votes
1 answer
135 views

Find character at given index in a sorted sub strings [closed]

For a given string say dbac the possible substrings are [d,db,dba,dbac,b,ba,bac,a,ac,c]. Sort them and concatenate to a string: ...
Learner's user avatar
  • 217
4 votes
2 answers
118 views

Find largest sum not involving consecutive values

There is a question to basically find the largest sum in an array, such that no two elements are chosen adjacent to each other. The concept is to recursively calculate the sum, while considering and ...
BlazeRod11's user avatar
1 vote
1 answer
212 views

Positive Segments

I'm trying to solve the following question: You have an array A of size n, containing −1 or 1 only, and s segments (not necessarily different). Each segment is defined by 2 integers li and ri (1 ≤ li ...
driver's user avatar
  • 232
-2 votes
1 answer
56 views

Market Portfolio Binary Search Tree [closed]

I'm trying to solve the following problem here: First line of input contains the number of days D. The next d lines contains a character c and a number x. If c is B, then buy stock . If c is S, then ...
driver's user avatar
  • 232
4 votes
2 answers
589 views

O(nlogn) Lexicographically minimal rotation code but tle on this particular case

Based on a small suggestion here , this code tries to find lexicographically minimal rotation (question) by successively comparing two adjacent substrings in the very left , that can potentially give ...
Aryaman 's user avatar
2 votes
1 answer
183 views

k-dice Ways to get a target value

I'm trying to solve the following problem: You have a k-dice. A k-dice is a dice which have k-faces and each face have value written from 1 to k. Eg. A 6-dice is the normal dice we use while playing ...
driver's user avatar
  • 232
3 votes
1 answer
1k views

Knock down tall buildings

I'm trying to solve the following problem: As you know Bob likes to destroy the buildings. There are N buildings in a city, ith building has ai floors. Bob can do the following operation. Choose a ...
driver's user avatar
  • 232

15 30 50 per page
1
2 3 4 5
36