All Questions
Tagged with time-limit-exceeded complexity
32
questions
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 ...
2
votes
2
answers
95
views
For two sequences N and M, display counts of elements n from N below each m from M up to the first n above m
A school's task:
There are two sequences n_tab and m_tab.
For every element m in m_tab ...
2
votes
2
answers
425
views
Can I further optimize this solution for HackerRank's “Making Candies”?
My C++ solution for HackerRank's "Making Candies" problem, reproduced below, is as optimized as I can make it and appears similar to what others say are optimal solutions. However, six of ...
2
votes
0
answers
114
views
Monotonic stack - complexity analysis
I tried following the official solution of LC975 (https://leetcode.com/problems/odd-even-jump/), using a monotonic stack - i.e., I reimplemented their solution (Approach 1) from python in C++.
TLDR ...
4
votes
1
answer
494
views
strstr implementation with python and sets
Please review my strstr implementation in terms of time/space efficiency and overall readability. I am preparing for a coding assessment coming up as I am looking to pivot my career from Physics to ...
5
votes
1
answer
705
views
01 Matrix is too slow when solved using DFS
I tried solving Leetcode 01 Matrix problem.
It is running too slow when solved using DFS approach.
Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell.
The distance ...
3
votes
1
answer
86
views
Count number of square integers in a given range of ints (faster function?)
The function below passes most test cases:
...
1
vote
0
answers
67
views
Why is my function timing out when run with a larger data set?
I am working on a Code Kata
...
2
votes
1
answer
94
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 ...
2
votes
1
answer
469
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 ...
4
votes
1
answer
893
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 ...
9
votes
3
answers
4k
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 ...
5
votes
1
answer
964
views
Finding the upper and lower bound using binary search
I am trying to solve this InterviewBit question
https://www.interviewbit.com/problems/search-for-a-range/.
My code for this seems to be working properly and it does give me the correct answers on my ...
0
votes
2
answers
48
views
Incrementing specified list values, with "catch-up" [closed]
I completed a coding challenge recently in which my function was to be given two parameters: N, the number of counters to be used (numbered 1 through N) - and A, an array of integers. Iterating ...
4
votes
1
answer
1k
views
Time complexity of Max counters
As per the instructions are given in MaxCounters-Codility,
You are given N counters, initially set to 0, and you have two possible operations on them:
<...