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.2k

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 ...
• 54.6k

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 ...
• 711

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 ...
• 67.6k

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.4k

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,221

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.8k
Accepted

Onion Run Festival (or the unexpected anagram for Union of Intervals)

Interval Your interval class is neat, well, structured in general. The hashCode/equals/compareTo contracts all look accurate. I like the Java-8-like use of the ...
• 97.1k

VSTO Write Dictionary To Range Extension Method

You have a lot of unnecessary vertical spacing which should be removed to improve readability. Based on the naming guidelines input parameter should be named using ...
• 50.1k
Accepted

A Range object for Java that partially implements List

A lot (most) of the methods from the interface are currently throwing an UnsupportedOperationException, either because the operation doesn't make sense (adding to the range), Start with an ...
• 13.5k

Parsing a list of single numbers and number ranges

Since the whole exercise is a string-transformation problem, I suggest performing it using a regex substitution. ...
• 143k
Accepted

Merging an overlapping collection of intervals

Some style issues: Space before { Spaces around -> Space after , No space before ...
• 8,508

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

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
Accepted

Collect subsequences of consecutive integers

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

Finding all intervals that match predicate in vector

Code Review This piece ...
• 9,249

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,317
Accepted

Formatting a date range, with shortening if the interval falls entirely within a calendar month

This is a self-contained problem, with well-defined inputs and outputs. To be maintainable, the code should reside in a function. You have three distinct cases, and maybe more: Start and end dates ...
• 143k

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

Parsing a list of single numbers and number ranges

Disclaimer: I'm not a Python programmer! Your code isn't that bad. It's readable enough for me to understand it. B+ for readability! Currently, you have this function: ...
• 6,066
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.7k

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)...
• 711

• 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.4k
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.7k