6 kyu
Perform operation to make string empty
223 of 380kaluginpeter
Loading description...
Algorithms
Logic
Puzzles
Fundamentals
Strings
Performance
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.
I really enjoyed this kata and improved my solution multiple times but it still times out after many attempts. If the author could review my latest solution and comment on whether I have a chance with the current approach it would be fantastic! Also I agree that the performance requirement makes this a very 'hard' 6 kyu...
Hi! Your attempt solution looks great, but can you think "whats make character last in the word"? And what is the best data structure to implement it?
Thank you for the engaging challenge. Although it took me many hours to solve, the process was highly enjoyable, and I gained valuable insights. In total, I went through seven iterations. I am a self taught beginner.
Your welcome! Glad that you liked kata!
Hello! I've made a python solution but it's timing out, any tips on how to improve the performance of my code?
You can look on other data structures(like hashtable) and think about differences between last characters and other characters
Thanks! It required some out of the box thinking, but now it's working
Your welcome)
Great kata
Thank you bro!
I usually skip the performance kata but this one drew me in and I enjoyed the challenge.
Thank you so much bro. Glad that u enjoed
Harder than it looks like at first glance.
Thank you that completed kata friend!
You're welcome, there's always a great chance to test your dynamic programming skills.
This kata was great ! A bit surprised on the performance aspect for a 6 kyu (looked more like a 4-5 kyu on that part imho), but it was a nice challenge to overcome !
Thanks for feedback!
At 6 kyu I would expect a more naive approach to work, for sure, but it's a really good problem to illustrate why optimization is important!
Thank you for feedback. Hope you enjoyed
I did! My kid, not so much. :)
Python fork
Approximately halves the amount of time needed to generate all the random tests. Leaves test parameters and author solution unmodified. I also removed the redunant
[::]
on all the inputs passed to the user, strings are immutable in Python.Approved by someone.
New fork of my JS translation with small changes to increase coverage and speed it up even more.
approved
Awesome Kata! I popped in back on Codewars after a long while and such performance challenge was exactly what I needed :) Thought it will be done in couple minutes, took a bit longer :D I agree with other comment that it would be good to mention in description performance will be important to pass random tests.
I really loved this Kata! Made a C++ Translation :)
Thanks you very much friend!
I'm new here, how do I post my solution? I plan on doing these katas in PowerShell and I'm not finding a way to submit solutions.
Never mind, I poked around and found out how.
JS Translation.
Please throw any brute force approach at it and see if it passes. Let me know. I personally tested it with two codes that had nested loops and both timed out.
approved by someone it seems
I believe most of the user that has solved this problem done it on a single attempt. Somehow, no one noticed that the assertion is not in the correct order:
test.assert_equals(complete_solution(word), last_non_empty_string(word[::]), f'Incorrect for strng {word}')
Thanks for feedback. Maked it
I think the performance tests need to be modified a bit/relaxed given this is only 6kyu. It would be so weird seeing that O(n) code almost has to time out in order to pass this Kata. I like the performance-restricted aspect, but I'm sure there is a way to penalize inefficient approaches while still keeping linear time answers at <=6s, no? Even the author's solution takes 11 seconds (12 is the timeout cutoff, mind you).
beta testers have voted 6 kyu on average with the current performance constraints in mind; I do think the performance criteria should be mentioned in the description though
Trust me I understand the rationale. This Kata without a performance restriction is more of a 7kyu task. I'm just not sure geting to a point where OP's answer is 1 second away from timeout should be how far the performance restriction is taken
I agree that ref sol should pass in a few seconds. Test cases are too strict.
Most of the runtime is spent generating the tests, not running the refsol.
The most naive optimisation possible (switching to using
random.choices
instead of repeated calls torandom.choice
) halves the runtime of the kata with refsol + authorsol.Fork fixing the slow Python test case generation
Runtime for author solution is down to 6.5s from 11.5s.
^That was approved by someone.
Leaving this open since I'm not sure if that is sufficient or I need to go further.
sufficient imo, or at least in an acceptable state now
6 kyu has been getting harder recently, huh?
Right? I didn't expected my O(n) solution to take 8 seconds at all for a 6kyu problem
anyone is allowed to participate in beta testing and vote on difficulty level, so please join and make your votes count
This can be difficult when there is literally only 1 day between creation and approval, especially so for any user that does find it more difficult.
I was just a few hours late for the party :(
Gotta keep refreshing that beta page
You are right Kacarott, though in general waiting 1 day or 1 month usually doesn't make much difference in number of users solving a beta kata lately.
Haskell translation
Thank you so much for translation
Resolved, Translation approved by author
Nice kata
Thank you so mush