Skip to content

Day 71 to 80

Miguel N. Galace edited this page Aug 19, 2019 · 6 revisions

Day 71

On to Day 2 of my HackerRank 30 Days of Code challenge (or Day 1 because in true programmer fashion they started counting from 0).

Again, still on very basic challenges. Just needed to read from standard input, perform some operations, then write to standard output. What did add some difficulty though was the language—as I opted to do it in C++—which I haven't touched in maybe 2 years. Glad to have done so though as I'd really like to brush up on my skills in that facet, so in that regard at least I am still learning.

Eager to start solving some actual problems though! Hopefully it picks up soon. 😅

Day 72

It didn't look like the HackerRank 30 Days of Code challenge was picking up any time soon, so I sought some problems on my own!

Wanted to start off easy since I'm pretty rusty from the time I've spent off. 😅 But stuck with C++ for the additional challenge. I ended up taking on the Sock Merchant problem, which was listed under their warm-ups. This one was as straightforward as problems will probably come here, and the difficulty really came more from dealing with C++ than the problem itself.

Still a step forward though! Will move on to something more challenging tomorrow!

Day 73

Went for a Medium difficulty problem today. Will be sticking with C++ for as long as I can manage!

The problem sounds simple enough. Given two lists, one of strings and another of queries, determine how many times items in queries occur in strings. The naive solution would be to iterate over strings in a loop over queries (or vice versa) while populating a result list as you went along. That would be wasteful however and, if we were to denote s and q to mean the sizes of strings and queries respectively, we would be left with an algorithm running in O(sq) time.

Solving the problem with a hash map will give you a solution that can scale much better and that will run only up to O(s) or O(q) time.

Day 74

Another Medium difficulty problem. And a more difficult one which I consciously sought.

This one is called New Year Chaos and it looks to be a kind of pathfinding problem. Proud I'm now able to recognize an approach to solving these kinds of problems fairly quickly. It would definitely not have come as quickly to me before all this. Right now I'm looking at a DFS solution, but I suspect that that will not be sufficient for 100% completion. I might have to resort to a smarter pathfinding algorithm, but I will satisfy myself with implementing the latter for now.

So far have just brainstormed a possible solution and written the input-parsing code and solution code. Haven't tried running let alone debugging it yet. Future Guigi can take care of the hard part! 😂

Day 75

Naturally, my code didn't compile right away (as it never does). 😂 But I worked through all the syntax errors and now have a running algorithm (yay!).

I do, of course, still have logic errors to deal with though. Been debugging for about an hour and I can now see the main point of failure. I had just been going through one path up to the very end and forgot to add the other possible paths to explore at every iteration. Not really sure what I was thinking there. 🤦‍♂ I should be doing DFS!

Also still have some cleaning up to do with my code. Will definitely make things more understandable when I get to it again.

Day 76

Finally got DFS implemented!

Running into timeout issues though. 😢 Guessing I won't be able to settle for just a blind DFS. Might have to go for something using a heuristic function, which, if memory of my class from 2nd year serves, is a means by which our algorithm can determine the "closeness" of its current output to the target. So instead of blindly picking one path over another, it can look at several options, determine which is most promising, then opt for that path and repeat!

Will look at how to implement A*, then apply that to this problem. Excited because this all makes so much more sense to me now than it did before. CS isn't such a mystery after all! 💪

Clone this wiki locally