Welcome to my personal website. I use this space to share some of my thoughts and software that I write in my free time. Sometimes I also publish photos. If you want to get in touch please use LinkedIn or Mastodon.
A decimal number is given as a list of integers. The number should be incremented by 1. The idea here is to iterate backwards through the list and start with the smallest digit. This way, this challenge can be solved in O(n). If after adding 1, the mod(10) is 0 it means we had an overflow and need to add one. If we didn’t we’re done and can break the loop. As a final check we need to make sure that there is no overflow in the end which would cause us to prepend the list.
Runtime: 67 ms, faster than 12.59% of Python3 online submissions for Plus One.
Memory Usage: 13.9 MB, less than 59.15% of Python3 online submissions for Plus One.
About the author
Friedrich Ewald is an experienced Software Engineer with a Master's degree in Computer Science. He started this website in late 2015, mostly as a digital business card. He is interested in Go, Python, Ruby, SQL- and NoSQL-databases, machine learning and AI and is experienced in building scalable, distributed systems and micro-services at multiple larger and smaller companies.