Hi, I'm Yanzhan . I'm interested in all kinds of algorithmic problems. Also, I'm fascinated with the C++ & Raku language. If you want to learn more about programming problems, C++ and Raku, please visit my Youtube Channel 📹, Twitter Account 📱 or GitHub Repo 📝.
- You may think computer programming and problem solving is very difficult, think again. Here's an example from Google Code Jam 2019 Qualification Round:
GCJ 2019 Qualification Round
Given a number n, suppose there is at least one digit 4 in this number.
How can you split number n into two numbers a and b, so that a + b = n
and there is no digit 4 in a and b.
-
This may seem difficult at first glance. Maybe one can iterate through 1 to n - 1, and check each possible pairs until the pair with desired properties is found. However, this solution requires O(n) 👎 time complexity which is too slow for this problem. Actually, there's a O(1) 👍 solution for this problem. Can you think of the correct solution?
-
It turns out that the O(1) 👍 solution is quite simple and intuitive. Just follow these steps:
- Replace all the digit 4 with digit 3, so this is number a.
- And replace all the digit 4 with digit 1, then we get number b. It's just that simple!
-
Algorithmic problems sometimes may seem daunting and unapproachable. However, once you have understood the underlying logic for the solution. It will become clear and simple, just like the above example. So just feel free to solve algorithmic problems. It's a wonderful experience.
As Donald Knuth has once said:
An algorithm must be seen to be believed.
So come with me, follow me at Youtube, Twitter or GitHub. Let's "see" the art of algorithm together!!
Also, the navigation list on my HomePage could guide you to read my articles about algorithm. If you are viewing my HomePage using a computer, then the navigation list is most likely directly displayed on the left column. Otherwise, maybe you are viewing my HomePage using a mobile phone, in that case, you may have to access the navigation list by clicking the menu button somewhere in the header. I've posted some articles about problems on HackerRank. Hope you enjoy the reading!
I'm Yanzhan . I'll update contents related to algorithm, computer programming, C++ and Raku language both on my Youtube Channel 📹 , Twitter Account 📱 and GitHub Repo 📝. Follow me so we can learn how to solve problems together. ✨