Tag Info

Accepted

Flipping coins performance

The code you have posted is straightforward and basic. Because of this, I'm going to assume you are not super-experienced with Python. I'll make some direct suggestions to go from your current code to ...
• 12.3k

Flipping coins performance

Thou shall not brute force. There is no reason to maintain the entire list of coin states, much less to perform actual flips. The state is easily recoverable from the sequence of ...
• 55.9k

Flipping coins performance

I think the problem authors maybe intended for people to use a data structure that allows for fast queries and updates. You can make it run in $Q\log(N)$ time by using a tree structure. First note ...
• 731

Merging Overlapping Intervals

This problem is well suited to an iterable method, rather than one that generates a list: ...
• 101

Collect subsequences of consecutive integers

@Peter Taylor has a good idea, but there is more to be improved You should add some tests Python is often described as Batteries included This is a perfect example to use ...
• 11.5k

Checking if two time intervals overlap

The code looks well presented, and it's clear how it maps to the problem statement. The one thing that's not well defined is how we deal with exact equality of times. I'm assuming that intervals are ...
• 72k
Accepted

Checking if two time intervals overlap

Negating the no-overlap case You mention four separate cases where two time intervals overlap. You then reduce it to three by pointing out that one case is really the intersection of two of the ...
• 21.4k

Coding Challenge Solution - Good Range

Don't force a class where a function is perfectly fine. The namespace std is not designed for wholesale importation, see "Why is ...
• 18.9k

Checking if two time intervals overlap

Your code uses an algorithm that directly tests for an overlap of time spans, but a simpler algorithm is to check for a non-overlap - to check for whether the time-spans are completely distinct. The ...
• 134

How to set an interval to std::map

Quite frankly it seems that you did not do what was asked from you. The text above assign gives you the requirements ...
• 4,231

Modeling and computing intersection between continuous intervals

Review You are constrained to float which makes your class only usable for a limited number of scenarios. I would like to be able to work with ...
• 13.9k

Finding the busiest time-frame in a parking lot

Naming Conventions MSDN, General Naming Conventions DO NOT use Hungarian notation: [dt]Start in getPickTimeframe() --> ...
• 853
Accepted

Collect subsequences of consecutive integers

Using yield is often simpler than building up a list to return. Here it would reduce ...
• 24.1k

Finding all intervals that match predicate in vector

If you want to write concise, idiomatic C++, the best way is to rely on the STL as much as possible, as a tool as well as an inspiration. So how would this algorithm be implemented in the STL? It ...
• 5,747
Accepted

Finding all intervals that match predicate in vector

Code Review This piece ...
• 9,374

Get consecutive integer number ranges from list of int

Your code takes a list, ensures it's sorted and distinct, then assembles and returns another list. This approach is problematic when the input is in fact a generator, in which case your code forces ...
• 2,622

Converting a range of integers from a string to an IEnumerable

Ok, some comments: Code style While there are no definitive laws about code style, most C# programmers are putting the opening brace { on a separate line. If ...
Accepted

Searching the number with the biggest amount of odd divisors in an interval

Bug Your code isn't always correct: >>> amountOddDivisorsOf(15) 3 Should be 4. Coding style The Python style guide recommends ...
• 18.4k

Flipping coins performance

Since Codechef seems to support numpy, I would propose a solution like this: ...
• 40.9k

Flipping coins performance

It looks like certain numpy operations give a very large constant factor speed benefit, as Graipher demonstrated in his answer. Graipher's solution is $O(QN)$ but is competitive with the \\$O(Q\log(N)...
• 731

• 171
Accepted

Find the intervals which have a non-empty intersection with a given interval

1. Review There is no docstring. What does the function find_intersections do? The text in the post is pretty clear, so you could use this as the basis of a ...
• 49.6k
Accepted

Counting integers that are within intervals

If you sort your values, you can then make an iterator on the sorted list, forward it to the lower limit, count until the first value is reached that is larger than the upper limit and discard all ...
• 40.9k
Accepted

Get consecutive integer number ranges from list of int

Your code is really complicated. First, your code should be abstracted a little more. It is not specific to feature IDs, therefore the terminology should not use these words. The same algorithm can be ...
• 21.2k
Accepted

"Can a list of meetings all be scheduled in a conference room?"

Like knut suggested, a simple solution would be to sort the meetings by start time and for each check if it conflicts with the next. E.g. given a list of meetings: ...
• 33k
Accepted

Counting the overlapping intervals in the union of two sets

Bugs I tried this test input: int[] a = {1, 10, 30, 60 }; int[] b = {2, 20, 40, 70 }; and your program returned 3. ...
• 28.5k

Checking overlap ranges between two prices

I am adding my comments at first glance. This is not a final review as this code needs lots of refactoring. Delete commented code Never keep commented code; it adds distraction while reading by ...
• 2,638
Accepted

Representing and Parsing an Open or Closed Range

I would check the result of range range = _RemoveSpaces.Replace(range, string.Empty); against string.Empty because that is ...
• 50.3k
Accepted

Add dash between more than two consecutive numbers and comma between other numbers in array

Sorry but no comments (yet) on the LINQ. Your first conditional has a logic error. You should be checking if orderedArray is null before you check if its length ...
• 6,257