Showing posts from February, 2018

Find Duplicated File in System

This problem requires more attention to the data structures and parsing then necessarily to the algorithm itself. Here it is Given a list of directory info including directory path, and all the files with contents in this directory, you need to find out all the groups of duplicate files in the file system in terms of their paths. A group of duplicate files consists of at least  two  files that have exactly the same content. A single directory info string in the  input  list has the following format: "root/d1/d2/.../dm f1.txt(f1_content) f2.txt(f2_content) ... fn.txt(fn_content)" It means there are  n  files ( f1.txt ,  f2.txt  ...  fn.txt  with content  f1_content ,  f2_content  ...  fn_content , respectively) in directory  root/d1/d2/.../dm . Note that n >= 1 and m >= 0. If m = 0, it means the directory is just the root directory. The  output  is a list of group of duplicate file pat

Ramanujan First Problem

Srinivasa Ramanujan is one of my heroes. A brilliant mind from Southern India (Chennai) who had an incredible talent for numbers and unfortunately a very tragic and brief life. If you want to learn more about him I recommend reading The Man Who Knew Infinity  instead of watching the movie. In the movie there is no, zero, mathematics. And if you learn about Ramanujan without appreciating his work in math it is as if you were learning about Einstein without appreciating his work in Physics. In the book you'll find one of the very first problems proposed by Ramanujan when he was still a kid. It was an infinite series (95% of his work revolved around infinity) where he asked all the top mathematicians in the world if they could solve it. Simply stated, here it is: What's the value of X? Top mathematicians all over the world jumped into this problem but with no success. They worked on it for months and months until they all, one by one, gave up. Finally Ramanujan gave away t

Would you put $20,000 in this investment? Think again!!!

You have $20,000.00 dollars that you want to invest. A close friend of you offers an outstanding investment opportunity, one that you just can't pass on. Here is how your friend explains the investment rules: You're going to put all your money into this account.  Every day the amount in your account will either go up by x%, or go down by x%, where x varies daily, randomly, between 0% (meaning you don't win or lose anything) to 99% (but it will never be 100%, meaning that you won't ever double your money or lose everything in a day). Are you still with me? OK, so far it doesn't sound that attractive. Seems like a toss of a coin. But your friend keeps going with the explanation: Alright, but here is the deal: with this investment you can have sequences of good days or bad days. These sequences happen continuously and randomly. When you land in a bad sequence, then you'll lose one day but you'll win the next day, guaranteed. BUT, when you land on a good s

LeetCode Improvisation Technique

The solution to this problem required a little improvisation technique, which some might say it is "cheating" but that's very subjective. The problem is this one, take a look: Initially on a notepad only one character 'A' is present. You can perform two operations on this notepad for each step: Copy All : You can copy all the characters present on the notepad (partial copy is not allowed). Paste : You can paste the characters which are copied  last time . Given a number  n . You have to get  exactly   n  'A' on the notepad by performing the minimum number of steps permitted. Output the minimum number of steps to get  n  'A'. Example 1: Input: 3 Output: 3 Explanation: Intitally, we have one character 'A'. In step 1, we use Copy All operation. In step 2, we use Paste operation to get 'AA'. In step 3, we use Paste operation to get 'AAA'. The solu