Skip to main content

All Questions

Tagged with
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
4 votes
2 answers
789 views

LeetCode Daily Problem: Remove adjacent duplicated elements

I was doing an exercise from LeetCode in which consisted in repeatedly deleting any adjacent pairs of duplicate elements from a string, until there are only unique characters adjacent to each other. ...
Rafael Carro Gaudim's user avatar
6 votes
1 answer
590 views

HackerEarth challenge: Lunch boxes

I was solving the lunch boxes problem on HackerEarth but as I submitted my solution most of the test cases were passed and the rest showed 'Time Limit Exceeded'. I would be very grateful if you could ...
Devansh Kumar's user avatar
1 vote
2 answers
1k views

How to do modulo thing fast (less execution time)

I was solving a question on a coding website and this website has a limit for execution time of code. My code takes 1.01 sec but the limit is 1 sec. I am unable to find any changes in my code that ...
Prince's user avatar
  • 125
1 vote
3 answers
673 views

Finding n-th smallest Palindrome number (where 1<=n<=5000 and the palindrome number must have odd number of digits)

I am working on this code from 3 days from a website called Codechef, the code compiles, executes and even give correct results but my code is taking 1.01 sec, but the time limit for question is 1sec,...
Prince's user avatar
  • 125
1 vote
2 answers
257 views

Determine whether bitwise-OR of sub-array is odd

Problem: Given an array A of N integers, you will be asked Q queries. Each query consists of two integers L and R. For each query, find whether bitwise OR of all the array elements between indices L ...
the_illuminated2003's user avatar
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 ...
Simon Jachson's user avatar
1 vote
3 answers
588 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 ...
pakgembus's user avatar
  • 189
3 votes
2 answers
235 views

Project Euler #7: Nth prime number

I was solving Project Euler #7 on Hackerrank but for two cases, execution time is more than 2 sec. Can you help with optimizing? I'm new to programming. ...
Aditya Singh's user avatar
3 votes
1 answer
298 views

A* search on 4x4 sliding tile puzzle scales poorly

I am trying to improve the time complexity of my A* search algorithm and I have tried approaching this from every which way I believe is possible. I believe I may be doing something fundamentally ...
Kubie's user avatar
  • 141
6 votes
3 answers
43k views

Minimum number of swaps required to sort the array in ascending order

Here is my problem statement. An excerpt: You are given an unordered array consisting of consecutive integers ∈ [1, 2, 3, ..., n] without any duplicates. You are ...
anand powai's user avatar
3 votes
1 answer
146 views

Program that finds prime numbers in a specific range

I'm kinda new to programming, and as a solution to an exercise, I made a program to find prime numbers in a range. It runs just right for small ranges of numbers, but for this exercise we are given a ...
dspanakis's user avatar
3 votes
3 answers
385 views

Find k-distinct partitions which contain at least two perfect squares

Problem Statement: A k-distinct-partition of a number \$n\$ is a set of \$k\$ distinct positive integers that add up to \$n\$. For example, the 3-distinct partitions of 10 are \$1+2+7\$ \$...
Phoenix's user avatar
  • 387
7 votes
2 answers
825 views

"Ease the Array" challenge

I'm working on this challenge: Given an array of integers of size N. Assume ‘0’ as invalid number and all other as valid number. Write a program that modifies the array in such a way that if next ...
Srivarun Neelakantan's user avatar
6 votes
3 answers
196 views

Finding black cluster size distribution for square grid at different probabilities of black elements (averaged over a certain number of iterations)

Context: I had asked a related question on Stack Overflow. On receiving several helpful hints from the commentators there, I could successfully implement averaging of the size distribution over a ...
user avatar

15 30 50 per page