All Questions
Tagged with time-limit-exceeded graph
34
questions
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) ...
1
vote
1
answer
524
views
Cheapest flights within k stops algorithm in JavaScript
The problem:
There are n cities connected by some number of flights. You are given
an array flights where flights[i] = [fromi, toi, pricei] indicates
that there is ...
3
votes
1
answer
531
views
Optimizing Dijkstra on grid Python (Microsoft Interview)
Given a square grid of size N, each cell of which contains integer cost which represents a cost to traverse through that cell, we need to find a path from top left cell to bottom right cell by which ...
-3
votes
1
answer
800
views
HackerRank | Roads and Libraries - Code Optimization
Major Edit: I wish people threw in a comment regarding what they are expecting instead of downvoting this question. I am quite appreciative of constructive feedback. I know it is only 3 people out of ...
2
votes
1
answer
221
views
Dijkstra's algorithm in graph (Python)
I need some help with the graph and Dijkstra's algorithm in Python 3. I tested this code (look below) at one site and it says to me that the code took too long. Can anybody suggest how to solve that? ...
6
votes
1
answer
278
views
Graph: Depth First Search (N citizens with pairs of friends)
I have solved problem 10608 on UVA Online Judge using Python 3.5.1. My solution works, but it takes too long to run when the online judge evaluates it.
Problem
There is a town with N citizens. It is ...
-2
votes
1
answer
149
views
How to work in linear time with DFS
I tried a Hackerrank problem and it gives me a successful message, it works fine for Hackerrank criteria.
The member states of the UN are planning to send 2 people to the moon. They want them to be ...
6
votes
1
answer
180
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 ...
3
votes
1
answer
2k
views
CodeChef's Tree MEX (Minimum Excludant) challenge
This code is a solution for CodeChef's Tree MEX problem:
Minimum excludant (or MEX for short) of a collection of integers is
the smallest non-negative integer not present in the set.
You ...
1
vote
0
answers
302
views
Graph-coloring solution using depth-first search
I'm trying to solve this question:
Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorate them.
The park consists of n squares ...
7
votes
1
answer
928
views
Hackerrank: Computer Game (max-flow problem with integer factorization)
I am working on a coding challenge from the Hackerrank site. Given two equal-length arrays of integers, with values from 2 to 109, find the maximum number of times we can remove a pair (Ai, Bj) where ...
7
votes
2
answers
208
views
Heights of Cats
I have an assignment to solve this problem. However, I have exceeded the time limit required, can anyone suggest where to improve my code?
Cats like to sit in high places. It is not uncommon to see ...
1
vote
2
answers
579
views
Determine whether a node is reachable
I am working on this HackerRank problem but running into time constraint issues.
Basically, given two arrays, we need to determine if the ith element of the second array is reachable by the ith ...
6
votes
1
answer
176
views
Finding intersting path in a graph
There is a question in a contest but it doesn't have any answer. I solve it but I get time limit for most of test case. Is it possible to improve my code or give a better approach?
Question
There is ...
7
votes
1
answer
792
views
Cheapest flights with at most k stops
This is the Cheapest Flights Within K Stops problem from leetcode.com:
There are \$n\$ cities connected by \$m\$ flights. Each fight starts from city \$u\$ and arrives at \$v\$ with a price \$w\$.
...