4 kyu
String -> X-Iterations -> String
106 of 338Jomopipi
Loading description...
Algorithms
Puzzles
Mathematics
Language Features
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Прохожу тесты, выводя время выполнения каждого из них, суммирую все полученные значения, получаю 9224. CodeWars даёт: Execution Timed Out (16000 ms), почему 9224 == 16 000 и почему так не считают зарплату? Решал на java
Вычислительная мощность твоего пк != вычислительная мощность той машины, где запускается код с сайта
This is a really nice kata, but I feel like it could be made even harder! The current reference solution seems quite suboptimal, this can easily be done in
O(n)
.Really enjoyed this kata! It took me about 8 hours total and I've learned a lot about manipulating arraylists 👍.
This comment has been hidden.
This comment has been hidden.
"Be read to optimize"? Forgot a letter there?
fixed
Please don't directly link to the trainer.
fixed
One of the most difficult (It took me hours!) and rewarding kata I've done so far.
In my opinion, the difficulty is way above 4 kyu, just look at the comments below and you'll see why...
I'm struggling with this for 5 hours in Python and I give up, I don't get why it doesn't work with huge strings?!
The caption made my day, thank you!
cool :D
This comment has been hidden.
I recommend adding a fixed test for
stringFunc(stringOfLength(999998), 99999)
where
stringOfLength(n)
is a string of lengthn
containing at least two distinct characters, e.g. (in Java):or just some random string.
You might as well take 1000001 for
n
.Is it possible to add some large tests so that naive solutions don't pass the time limit? I found, that many submitted solutions timeout on this test:
length = 2000006, x = 998524817
C# has anyone managed to pass the test suite without timing out?
I managed to get tests by passing in 'Console.WriteLine($"{s} {x}")' so i could get the input values and expected outputs in order to run the tests locally, they all pass in 20ms in total (all thirteen tests). My computer is over 5 years old.
When I try my solution on the site it times out in 12000 ms without passing (or failing) any tests.
I really enjoyed trying to solve this kata, it was really good fun. Am happy to share code (there isn't very much of it).
Any help would be really appreciated. Thanks in advance : )
Same issue!
12 seconds... Even if go for the most naive solution it should work.
How come, that it's not?
pretty sure i am not that good to solve in the most efficient way but i passed the Test and that's Somehow good for me :)
So i have a question is there any previous Kata that have just the first part ?
and i really wanna see the result in c# too so hope to know if there's any news about it
My code is failing for long strings(all variations of n) but is passing all medium and small strings(all variations of n). Could somebody point me in the right direction for this.??
This comment has been hidden.
nvm..got it.
This comment has been hidden.
Passed: 2 Failed: 0 Exit Code: 1; Execution Timed Out (16000 ms) - I keep getting this. Does this just mean my solution isn't optimised enough? I assume I am passing the "a_test_of_large_x" and "a_3rd_test" but failing a different one?
you need to change your algo to get something faster.
Alright, will do!
C# Translation added.Please review and approve~
approved
Does this kata actually work on python? I tried like 10 versions, I did give up and copy pasted someone else's solution so see if it was me and it doesn't work either. Browser chocker timed out i guess
"Browser Choker" is no longer part of the test suite.. goodluck
After spending a long time trying to figure out how to optimize my code I finally decided to give up. However after I did, I tried previous solutions and all of them timed out (including the one from the author).
what language?
Java
ill get to it as soon as I can
Tests adjusted, sorry you had to have this experience.
This comment has been hidden.
There is no error with it, it is just a performance test. If 10 people already solved it in Java, it is possible for you too, aslo.
ok, then I assume that a solution should have a linear time complexity
it does have quite a constraint.. not sure if it's linear though, but maybe
I have solved your another very similar kata https://www.codewars.com/kata/string-%3E-n-iterations-%3E-string/java.
And I took a look at the code of your final test class. You are using inefficient brute force algorithm as a reference solution and your random tests actually are not random because the array with possible lengths of the tests strings is hardcoded in your test class.
Maybe I'm wrong but I think that in the current kata you have created very similar test class. And your reference solution takes too much of execution time. For this reason the timeout is triggered and no solution can pass the test. I'm not sure exactly why, maybe because the performance of the code executor has decreased since you published the kata.
hint: there is a silly math trick behind.
This comment has been hidden.
I know it's a little late, but I did adjust the tests just a bit. Goodluck.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
avoid string concatenation
Why do I see this everytime ?!
https://i.imgur.com/PKVobP6.png
With exit code: Execution Timed Out (12000 ms)
because your solution wasn't fast enough.
This comment has been hidden.
It seems your code is not passing all the tests
This comment has been hidden.
Test cases are of a million length so just imagine reversing that long strings again and again till the period
There is mathematical pattern you need to find out
or at least just follow the string and see if there's a faster way to fun reverse it :)
This comment has been hidden.
as far as producing the correct output, your code seems fine. But this is a performance kata, so you will need to try to find some shortcuts. BTW this is a question, not an issue.
I have no problems passing the test cases, but i ll always get a time out when i try to attempt. I dont know on which test case i cant pass, may u can help me?
post your code with a spoiler flag
This comment has been hidden.
so u can help me?
no, this code produces errors.. looks like c#, which is not currently supported by this kata.
Negative
x
for one of the tests in Java.which test?
BROWSER_CHOKER
finally found it, thx
soo.. very satisfied?
:) Approved.
"F" YEAH!!
This comment has been hidden.
there's no negative x being passed in
@ecolban: that's typical of cw servers' trouble, just try again later.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
what the... xo
how many tests did you put in there?? 11000 passed and still not enough. Here you have a big problem, because the very same algo I use in python is passing in java.
hmm idk I have:
This comment has been hidden.
yes, but you use a very different approach than for the other kata. but anyway, the main problem is that the two languages are not compliant about their respective difficulty.
mm I guess I should tighten up the java tests. the problem is that with the way im doing it im doing a calculation that goes over 2^63 for finding the cycle (if the string length is greater than 63) so either I limit the lenghts or I do something else to speed it up. btw fixed the tests, you may want to look at it
if you do that, I guess nobody will find how to complete it (almost)
This comment has been hidden.
ok. I'll change my ranking after that, then.
Note that you'll have to make it heavier in python too, then. Using the kind of technics I used in the other version.
This comment has been hidden.
This comment has been hidden.
your solutions got invalidated ;)
not enough: this one and that one should be invalidated too: they use a very less performant approach. Your reference should be either this one or that one.
for now, I have one only line to add in my java solution so that it passes again (the line you added in the first link). Note: your solution doesn't show up in python.
your own python solution often fail the tests. Needs improvments.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
no, that's bad! Your random tests are now actually almost fixed tests! (not talking about what's in the strings, but the lengths)
This comment has been hidden.
I think it's pretty good now :P
yeah, you just stepped back to what it was before... x/ Nothing in common with what we talked about... I believe you're just not enough "in" yet, to manage this kind of constraints correctly.
what's wrong? everybody else's solution got invalidated, the tests are way tougher now.
the problem is still the same: too much variability in the performances requirements. Your solution:
are you looking at java? it's passing every single time for me. I haven't edited python yet
ah, I was using python... x)
Ah yeah, looking at the java test suite, that seems far better. Ok, that "smells good", then.
I want to do the same to python, but without affecting the nice structure
sooo... in both versions, my solution is the only one that passes
let see what will happen, now.
This comment has been hidden.
I added a new test, is it ok?
.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Well, I'm trying to merge them... I don't find any speed improvment... :/
This comment has been hidden.
This comment has been hidden.
yes omg, let me change that
This comment has been hidden.
This comment has been hidden.
I'll change it now
ok, keep me posted
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
The expected result is incorrect: you're converting a
long
toint
before doing your calculations.This comment has been hidden.
.