Skip to main content

All Questions

4 votes
2 answers
513 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
  • 361
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
  • 361
6 votes
1 answer
129 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
3 votes
1 answer
96 views

Java i/o speed less than python i/o while printing an array

Motivation: I was solving an array based i/o problem and encountered Time Limit Errors, it was later found that the code for java ran roughly 10x slower than the ...
the_illuminated2003's user avatar
2 votes
2 answers
613 views

CSES - Number Spiral - Java TLE

My java code for CSES Introductory problem Number Spiral gives TLE for large inputs, like Input : 100000 170550340 943050741 121998376 943430501 689913499 770079066 586095107 933655238 … (First line/...
Deepti Shahi's user avatar
3 votes
1 answer
321 views

Prime factorisation in java

I came across this question in a coding contest (Java-restricted) and I got TLE. I am unable to provide the link of the question as the contest is closed now. Can I know how can I optimise this? Four ...
PRANATHI G's user avatar
3 votes
0 answers
198 views

Count unique subsequences

I came across this question in a coding competition (Java-restricted) and I got a time-length-exceeded. I am unable to provide a link as the contest is closed now. Can I know how can I optimise this? ...
PRANATHI G's user avatar
-4 votes
1 answer
86 views

Time limit exceeds in this simple program [closed]

Link to problem: https://www.codechef.com/JUNE20B/problems/EVENM Iam trying to solve a simple problem challenge, but getting TLE. I had a different approach earlier, so tried this, again with no ...
drac_o's user avatar
  • 101
4 votes
3 answers
404 views

How can I optimize my code that uses nested for loops?

I am working to solve a problem where I need to determine if a Point lies on a line connecting two other Points. For example, ...
mlb's user avatar
  • 43
4 votes
0 answers
79 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 ...
RE60K's user avatar
  • 1,466
4 votes
1 answer
139 views

INCARDS SPOJ challenge

Question- In short question says that you have N bus stops and K bus routes. Every bus routes is linked to two bus stops. Each route has some cost of travelling. It says one person visit any ...
Ladoo's user avatar
  • 69
8 votes
4 answers
7k views

Finding the maximum element of a Stack

I have been solving this problem of Hackerrank recently .. https://www.hackerrank.com/challenges/maximum-element A little bit about the problem You have an empty sequence, and you will be given N ...
Tilak Madichetti's user avatar
5 votes
1 answer
223 views

How to lose plants and aggravate people

Courtesy of a few posts around here I've discovered HackerRank. Poisonous Plants is one of their challenges. Of course, skip the following if you'd like to try it yourself. Challenge: There are \$...
Legato's user avatar
  • 9,839
2 votes
1 answer
114 views

Performance of the String searching algorithm

I am trying to solve a string matching question mentioned here. I recently learned the Knuth–Morris–Pratt algorithm and tried to implement it to solve this question. But I am getting a TLE for this ...
Alpa8's user avatar
  • 121
8 votes
1 answer
4k views

Calculate the running median

I'm trying to solve a challenge where you need to calculate the median every time you add a number. say you have a list of numbers: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ...
Nilzone-'s user avatar
  • 1,436

15 30 50 per page