Ad
  • Custom User Avatar

    this is bad practice, instead of using multiple if, use else if. else if only checks the other conditions if the first one resolved to false, yours will always be checked in any case. Also the last if should be moved inside the scope of second if to only check it if the current parenthesis is a closing parenthesis.

  • Custom User Avatar

    This has been happening to me for the past week. I don't know what the problem/solution is.

  • Custom User Avatar

    yah, gotta say this seemed terribly easy for a 4 kyu kata. I hit submit expecting to wait 15 seconds and get a "timeout" error from test cases with absurdly massive values of k and n, but nope, straight-forward, naive implementation worked. :shrug:

    I was solving in go, for the record.

  • Custom User Avatar

    This is cool! Nice work

  • Custom User Avatar

    A little bit simple...

  • Custom User Avatar

    Thank you for the compliments.

    Most programming competitions are aimed for high school coders, so it will be hard for college students to start; however, there are still many local competitions that occur everywhere, so that is a good place to start. Ironically, my coding teacher told me to start practicing for competitions by using this site beacuse the questions here come out of competitions and job interviews sometimes.

    I admire students with jobs. Having many friends in the college I will go to, I understand the time pressure. I wish you good luck with your programming!

  • Custom User Avatar

    Thank you for the information. I checked out your profile and am pretty impressed. I want to get into programming competitions but I have a lot of practice ahead of me and I'm a full time student with a full time job. Do you have any tips on getting started?

  • Custom User Avatar

    I thought the same thing, but it ran in about the same time as the conventional code.

    The reason for this is than my code has two loops, but each loop only has one check, making it O(2N) like you said. However, the conventional code has one loop, but two checks in it. This makes it O(2N) as well. This code did run slightly faster, but that probably has to do with server load - not efficiency.

    To answer your question about the competitions, my team likes to have clean and clever code that looks better for judges. This takes more memory, but memory isn't much of a factor in the code's readability and use of convention. Run time is a factor though.

    Thank you for your feedback! :)

  • Custom User Avatar

    I like this solution a lot. I have one question though: doesn't the str.replace() method create a whole new String in memory? If that's the case, this solution uses up to 3x more memory than necessary. Also, I imagine that str.replace() iterates through each character in the String anyway, resulting in O(2N) instead of O(N) that would have resulted in iterating through the string once and counting. Do they take inefficiencies like this into consideraton in programming competitions?