I’ve found this interview question at GeeksForGeeks and decided to actually code it in C++. The program currently prints the “value” of the horses (which is inaccessible by the coder so they can’t just look up who is number 1) and then proceeds to sort them and find the position of numbers 1,2 and 3 in a 5x5 matrix with the solution being a minimum of 7 races.
Here’s the Github repo: https://github.com/Shroomerian/HorseRacing
My personal preference is to leave comments where it’s not directly clear what the code does. Using “good” variable & function names can make the code usually somewhat self-documenting, but that’s not always enough.
Yeah I understood why you used that approach, and I’m not a c++ expert myself, just wanted to point out some other options.
It makes no difference visibility-wise if you have a variable that is local to a function vs a private member of a class that’s just used by said function.
Huh, that sounds odd. Never done anything with LeetCode, but would be interested into seeing what was going on there. If you want to use sets, check whether you need ordering (most likely you don’t) and go with
std::unordered_map
.Absolutely not. I see lots of value of optimizing and cleaning up code, there is so much to learn which will help you write better code in the future. I have a bunch of programming projects that I never fully finished and you could also call them a waste of time - who would play with my gameboy emulator without gui etc? No one besides me :) But it was more about the journey and learning things. So go for it and code things you find interesting, that’s a good way to stay motivated.
Good luck with admissions. Putting effort into it in your spare time and as a hobby is great and shows dedication, exposing your code to “the internet” and asking others for feedback is also a great way to grow - way to go!