Sort 8 Discussions, By:
Please Login in order to post a comment
I passed the first test case and the program is giving correct results for custom inputs.
But it is giving runtime error for other test cases..
This Hacker Rank question looks similar to the original Project Euler question, but it's actually quite different.
For the start, Project Euler only requires you "count" the character differences, while Hacker Rank requires you to actually convert to the short form.
More problematic difference is that their inputs follow different rules. All of Project Euler inputs are still "valid": e.g. only one 'V' can appear in a string.
I ended up having two different solutions for these questions. I had a solution passing all tests in Hacker Rank, but failing Project Euler.
Is there any clean approach without first calculating the value in decimal form? I've passed every test cases of this problem, but I hated it. For the original problem, I used a dict to count the number of consecutive occurrences, and increment total += 3 or += 2 accordingly. But it seems this approach is not suitable for the HackerRank version, where there could be invalid input like VVVVVVVVV.
total += 3
Yes. It can be done by a series of string replace.
Perhaps it's easiest to first consider how I II ... IIIIIIIIIIIIIIIIII IIIIIIIIIIIIIIIIIIII can be converted to I II ... XIX XX by a series of replacement rules. Since the relationships between IVX XLC CDM are the same, they can be governed by similar sets of rules.
I solved this question 100% all test cases cleared.
But I want to know what all other approach can be used for this problem,
I used HashMap to put all key values and printed them using Reminder and Modulas Strategy.
for eg 71 will be LXXI
and so on..
Pretty much the same, except I used a dictionary and three string arrays -- one for each of the rightmost three digit places -- instead of a hash map.
Can we be sure that the test cases are valid? For example, they don't include something like "IIIVII" (which is ambiguous) or "IM" (which is not syntactic)?
It says that all the test cases are in descending order.
Any special test cases to note? I used this same code with the Project Euler question and got the correct answer.
can i get some sample test case??.. fr dis #89
I was failing all but the first test case until I realized that I wasn't accounting for the example case given in the description (IM should be CMXCIX) -- for that case you need to remember I can be subtracted from 10 as well as 5.
did you pass all the test cases??
how can i see other test cases ???
You can't see other test cases for contests.
1519 is a pretty good test case :P
No more comments