Showing posts from July, 2018

Walking Robot Simulation

Latest problem from Leetcode is this one: Now the description of the problem doesn’t seem super accurate since in reality what the author is asking is: as the robot walks, for each step there will be an Euclidean distance from that position to the origin. Return the maximum Euclidean distance to the origin as the robot walks the course . Also, it wasn’t clear that one could have duplicated obstacle. I want to believe that many Leetcoders must have been confused and that might be the reason that there are more thumb downs than ups. I failed submission few times because of these misunderstandings: The problem is a simple traversal (some attention to details required) with usage of a hash table for a quick lookup into the obstacles. To quickly access the hash table, use the following trick to build the key: suppose that you want to build a key for index (a,b) with the following constraints: 0<=a<=N

Reordered Power of 2 - Medium Difficulty

Hello dear friends, problem is this one: Starting with a positive integer  N , we reorder the digits in any order (including the original order) such that the leading digit is not zero. Return  true  if and only if we can do this in a way such that the resulting number is a power of 2. Example 1: Input: 1 Output: true Example 2: Input: 10 Output: false Example 3: Input: 16 Output: true Example 4: Input: 24 Output: false Example 5: Input: 46 Output: true This is a medium-difficulty problem, but if you pay close attention to the constraints you can solve it relatively easy. First, the upper limit is really small: 10^9. The approach that can be taken is to use a static hashtable (static so that you don't have to recompute it all the time) holding all the powers of two between 0 and 10^9. There won't be many since they grow exponentially fast. But you don't want to j

IBM Ponder This July 2018: Obscure Triplet

The IBM Ponder This are fun coding/math/logic challenges that are sponsored by IBM Haifa on a monthly basis, and that's been going on for several years now. Some challenges are really obscure and complex, others can be solved with the help of some programming language. I've managed to solve three in the past - the prize is just bragging rights with your name posted on their challenge pages: The latest one was posted on July 2018, and this is it: : " This month's challenge is based on a riddle I heard from Odelia Moshe Ostrovsky (thanks!). Let's call a triplet of natural numbers "obscure" if one cannot uniquely deduce them from their sum and product.