<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8486091826623887572</id><updated>2012-01-21T05:22:30.641-08:00</updated><category term='C++'/><category term='yahoo'/><category term='search engine companies'/><category term='threads'/><category term='SEO'/><category term='web2.0'/><category term='adsense'/><category term='interview questions'/><category term='puzzles'/><category term='maps'/><category term='traffic'/><category term='Ideas'/><category term='Facebook'/><category term='hashing'/><category term='Google'/><category term='deadlock'/><category term='Programming techniques'/><title type='text'>Random Puzzles</title><subtitle type='html'>Random Tech stuff</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://randomtechpuzzles.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://randomtechpuzzles.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>eng6537</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>14</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8486091826623887572.post-2882799602143886800</id><published>2007-07-27T17:38:00.000-07:00</published><updated>2007-07-27T17:51:51.348-07:00</updated><title type='text'>Facebook Superpatterns puzzle - The solution 2</title><content type='html'>My earlier blog &lt;a href="http://randomtechpuzzles.blogspot.com/2007/07/facebook-puzzle-superpatterns-solution.html"&gt;post&lt;/a&gt; had a brute force approach to solving the super patterns puzzle. The order of the program was in the order of n!. Didnt think it was worth coding it up. Might use it to validate this new solution. The solution is based on building larger superpatterns from smaller ones. This is how the solution would look like ..&lt;br /&gt;Take a 2 -subpattern for eg. The subpatterns would be&lt;br /&gt;{1,2} and {2,1} .. the superpattern is {1,3,2} other "superpatterns" that are not combinatorially smallest are {2,1,3}, {2,3,1} and {3,1,2}.&lt;br /&gt;We can build higher superpattern from lower ones like this.&lt;br /&gt;For the 2-subpatterns to become a 3 -subpatterns, it would have to satisfy ..&lt;br /&gt;{&lt;span style="color:#ff0000;"&gt;3,&lt;/span&gt;1,2}&lt;br /&gt;{&lt;span style="color:#ff6666;"&gt;3,&lt;/span&gt;2,1}&lt;br /&gt;{1,&lt;span style="color:#ff6666;"&gt;3,&lt;/span&gt;2}&lt;br /&gt;{2,&lt;span style="color:#ff6666;"&gt;3,&lt;/span&gt;1}&lt;br /&gt;{1,2&lt;span style="color:#ff6666;"&gt;,3&lt;/span&gt;}&lt;br /&gt;{2,1&lt;span style="color:#ff6666;"&gt;,3&lt;/span&gt;}&lt;br /&gt;Which in a way means that we will have to add a "higher" element in the sequence or superpatterns that generated the lower or 2-subpatterns to get the 3-subpattern.&lt;br /&gt;&lt;br /&gt;The trick if figuring out the smallest combination of adding this additional number. More commong soon ...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486091826623887572-2882799602143886800?l=randomtechpuzzles.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://randomtechpuzzles.blogspot.com/feeds/2882799602143886800/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8486091826623887572&amp;postID=2882799602143886800' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/2882799602143886800'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/2882799602143886800'/><link rel='alternate' type='text/html' href='http://randomtechpuzzles.blogspot.com/2007/07/facebook-superpatterns-puzzle-solution.html' title='Facebook Superpatterns puzzle - The solution 2'/><author><name>eng6537</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8486091826623887572.post-4960123682787945020</id><published>2007-07-22T15:51:00.000-07:00</published><updated>2007-07-24T11:26:03.626-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='interview questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Facebook'/><category scheme='http://www.blogger.com/atom/ns#' term='puzzles'/><title type='text'>Facebook puzzle - SuperPatterns the solution</title><content type='html'>Here's my solution to the facebook superpatterns puzzle. The actual puzzle is available &lt;a href="http://www.facebook.com/jobs_puzzles/?puzzle_id=8"&gt;here&lt;/a&gt;. The solution will follow a pattern that I used to solve the &lt;a href="http://randomtechpuzzles.blogspot.com/2007/07/facebook-puzzles.html"&gt;GridFlip puzzle&lt;/a&gt;, again from facebook.&lt;br /&gt;&lt;br /&gt;This solution is completely based on information on superpatterns available from this &lt;a href="http://en.wikipedia.org/wiki/Superpattern"&gt;wikipaedia article&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Identify characteristics of the problem space and define rules that will reduce it.&lt;br /&gt;1. The relative weights of the numbers in the superpattern are important, the actual numbers dont matter. What I mean by that is, if [25314] is a superpattern, then adding one to all numbers we get [36425] which is also a super pattern. Based on this, we can safely assume that if n is the length of the super pattern, the possible numbers in the pattern can only be 1 to n.&lt;br /&gt;&lt;br /&gt;2. If [25314] is a super pattern, then inverse [41352] is also a super pattern. This true because if 123 is present in a subpattern, 321 is also present in the subpattern ??&lt;br /&gt;&lt;br /&gt;3. There can be no repetitions.&lt;br /&gt;&lt;br /&gt;4. Minimum lenght of a super patterns with a k-subpattern is k+k -1 (The inclusion and exclusion principle in the wiki page).&lt;br /&gt;&lt;br /&gt;Based on the above principles. The size of a problem space for a k-subpattern (subpattern of size k) will be ..&lt;br /&gt;*Minimum lenght of the superpattern n = 2*k -1.&lt;br /&gt;*Number of possible number we can generate for n = n! (Assuming numbers are unique).&lt;br /&gt;*Since the inverse is equal problem size = n!/2;&lt;br /&gt;&lt;br /&gt;so if we have a 3-subpattern (k=3), which has 3! permutations, we have to make sure that each of the n!/2 possible solutions satisfy the k! subpatterns.&lt;br /&gt;&lt;br /&gt;=&gt; Complexity of the algorithm = (2*k-1)!/2 * k!&lt;br /&gt;&lt;br /&gt;Using the above rules, I constructed a base solution set, assuming k =3 -&gt; n =5.&lt;br /&gt;The solution set would look like this.&lt;br /&gt;12345, 12354 ... 54321.&lt;br /&gt;&lt;br /&gt;*We can further reduce the problem by adding more constraints on the possible values for each number in the superpattern. What I mean by that is ..&lt;br /&gt;lets say x1, x2, x3 .. xn are the number in the superpattern and if y1, y2, y3 ..yk are the elements in the subpattern. Each subpattern must have k number =&gt; the first number in the subpattern y1 can be selected from numbers x1- xl (where l = (n-k) +1), similarly y2 can be selected from x2 - xl (where l = (n-k) +2).&lt;br /&gt;Here's an example .. if [25314] is the superpattern the subpatterns of length 3 can be&lt;br /&gt;214, 514, 314 =&gt; the first number in the subpatterns is selected from 253.&lt;br /&gt;254, 234, 214 =&gt; the first number in the subpatterns is selected from 531.&lt;br /&gt;&lt;br /&gt;Output Rule.&lt;br /&gt;*If you look at the subsets you will notice that the first number in the subset will have all possible relative values. What I mean is that for a 3-subset, the first number must be 1,2,3 (Relative weights). The same with the remaining numbers.&lt;br /&gt;&lt;br /&gt;We now have a possilbe solution set.&lt;br /&gt;Rules that we can impose on the solution set ie, the set of possible values for the first number in the subpattern must contain the largest in the sequence, the second largest in the sequence .. the smallest in the sequence ..&lt;br /&gt;&lt;br /&gt;The solution:&lt;br /&gt;Generate possible solutions and validate against the output rules.&lt;br /&gt;&lt;br /&gt;Solution and source code to this puzzle comming soon ..&lt;br /&gt;&lt;br /&gt;Find something wrong with this solution, or want to add something .. please add a comment or email me at my gm@il acccount blogtamma.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486091826623887572-4960123682787945020?l=randomtechpuzzles.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://randomtechpuzzles.blogspot.com/feeds/4960123682787945020/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8486091826623887572&amp;postID=4960123682787945020' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/4960123682787945020'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/4960123682787945020'/><link rel='alternate' type='text/html' href='http://randomtechpuzzles.blogspot.com/2007/07/facebook-puzzle-superpatterns-solution.html' title='Facebook puzzle - SuperPatterns the solution'/><author><name>eng6537</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8486091826623887572.post-1838722410130426571</id><published>2007-07-21T01:06:00.001-07:00</published><updated>2007-07-21T12:51:38.562-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Programming techniques'/><category scheme='http://www.blogger.com/atom/ns#' term='threads'/><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Using a counting semaphores to control queue access</title><content type='html'>Controlling data transfer between threads in a multi-threaded application can be quite a challange. I recently had a problem where a thread in a program was generating data and another thread is needed to process the data. This a classic problem for any web service. There is a thread that listens to data on a socket. As soon as it receives data on a socket it build a request / or can just read data and add it to a queue.&lt;br /&gt;Once the data hits the queue, another thread reads the data from the queue and processes the data.&lt;br /&gt;This is a classis multi-threaded problem, there are two threads trying to access a shared resource - the queue. The solution to this problem, use a counting semaphore to restric access to the queue. The pseudo code for this would look like this.&lt;br /&gt;&lt;br /&gt;This is also a classic case of the producer consumer design pattern.&lt;br /&gt;&lt;br /&gt;Here's the sample pseudo code ..&lt;br /&gt;Main thread..&lt;br /&gt;&lt;br /&gt;[... do something ...]&lt;br /&gt;Semaphore _queueSema = new Semaphore(0,1000); //Initial count 0, max 1000;&lt;br /&gt;[.....]&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Producder Thread ..&lt;br /&gt;queue.Enqueue(item);&lt;br /&gt;_queueSema.release();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Consumer Thread ..&lt;br /&gt;_queueSeam.Aquire();&lt;br /&gt;queue.Dequeue();&lt;br /&gt;&lt;br /&gt;Note: This is assuming that there is only one consumer and one producer. If there are multiple consumers and producers the queue access will have to be protected by a CriticalSection or some mutual exclusion class and its always a good idea to do this.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486091826623887572-1838722410130426571?l=randomtechpuzzles.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://randomtechpuzzles.blogspot.com/feeds/1838722410130426571/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8486091826623887572&amp;postID=1838722410130426571' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/1838722410130426571'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/1838722410130426571'/><link rel='alternate' type='text/html' href='http://randomtechpuzzles.blogspot.com/2007/07/using-counting-semaphore-to-control.html' title='Using a counting semaphores to control queue access'/><author><name>eng6537</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8486091826623887572.post-1823883263858917633</id><published>2007-07-21T00:17:00.000-07:00</published><updated>2007-10-02T02:47:26.520-07:00</updated><title type='text'>SiteMap</title><content type='html'>&lt;a class="__feedview__feedItemUnreadTitleLink" href="http://randomtechpuzzles.blogspot.com/2007/07/facebook-puzzles.html"&gt;Facebook GridFlip - The solution&lt;/a&gt;&lt;br /&gt;&lt;/url&gt;&lt;url&gt;&lt;loc&gt;&lt;a class="__feedview__feedItemUnreadTitleLink" href="http://randomtechpuzzles.blogspot.com/2007/07/facebook-puzzle-gridflip-problem.html"&gt;Facebook puzzle GridFlip - the problem&lt;/a&gt;&lt;/url&gt;&lt;br /&gt;&lt;url&gt;&lt;loc&gt;&lt;a class="__feedview__feedItemUnreadTitleLink" href="http://randomtechpuzzles.blogspot.com/2007/07/thread-deadlocks.html"&gt;Thread Deadlocks&lt;/a&gt;&lt;/url&gt;&lt;br /&gt;&lt;url&gt;&lt;loc&gt;&lt;a class="__feedview__feedItemUnreadTitleLink" href="http://randomtechpuzzles.blogspot.com/2007/07/getting-google-to-crawl-your-site.html"&gt;Getting google to crawl your site&lt;/a&gt;&lt;/loc&gt;&lt;br /&gt;&lt;/url&gt;&lt;url&gt;&lt;loc&gt;&lt;a class="__feedview__feedItemUnreadTitleLink" href="http://randomtechpuzzles.blogspot.com/2007/07/find-missing-number.html"&gt;Find the missing number&lt;/a&gt;&lt;/url&gt;&lt;br /&gt;&lt;url&gt;&lt;a class="__feedview__feedItemUnreadTitleLink" href="http://randomtechpuzzles.blogspot.com/2007/07/anagram-generate-all-possible.html"&gt;Anagram - Generate all possible dictionary words from a given word&lt;/a&gt;&lt;br /&gt;&lt;/url&gt;&lt;url&gt;&lt;a class="__feedview__feedItemUnreadTitleLink" href="http://randomtechpuzzles.blogspot.com/2007/07/find-number-of-bits-set-in-number.html"&gt;Find the number of bits set in a number&lt;/a&gt;&lt;/url&gt;&lt;br /&gt;&lt;url&gt;&lt;loc&gt;&lt;a class="__feedview__feedItemUnreadTitleLink" href="http://randomtechpuzzles.blogspot.com/2007/07/probability-function.html"&gt;Probability function&lt;/a&gt;&lt;br /&gt;&lt;/url&gt;&lt;url&gt;&lt;a class="__feedview__feedItemUnreadTitleLink" href="http://randomtechpuzzles.blogspot.com/2007/07/why-mobile-companies-should-get-into.html"&gt;Why mobile companies should get into maps and traffic&lt;/a&gt;&lt;/url&gt;&lt;br /&gt;&lt;a href="http://randomtechpuzzles.blogspot.com/2007/07/thread-deadlocks.html"&gt;Thread Deadlocks&lt;/a&gt;&lt;br /&gt;&lt;url&gt;&lt;loc&gt;&lt;a class="__feedview__feedItemUnreadTitleLink" href="http://randomtechpuzzles.blogspot.com/2007/07/google-interview-questions.html"&gt;Google Interview Questions&lt;/a&gt;&lt;br /&gt;&lt;/url&gt;&lt;/urlset&gt;&lt;a href="http://randomtechpuzzles.blogspot.com/2007/07/using-counting-semaphore-to-control.html"&gt;Using a counting semaphores to control queue access&lt;/a&gt;&lt;br /&gt;&lt;a href="http://randomtechpuzzles.blogspot.com/2007/07/facebook-puzzle-superpatterns-solution.html"&gt;Facebook puzzle - SuperPatterns the solution&lt;/a&gt;&lt;br /&gt;&lt;a href="http://cpprocks.blogspot.com/2007/09/site-map.html"&gt;Facebook Superpatterns puzzle - The solution 2&lt;/a&gt;&lt;br /&gt;&lt;a href="http://cpprocks.blogspot.com/2007/09/site-map.html"&gt;CPPRocks&lt;/a&gt;&lt;br /&gt;&lt;a href="http://testingrocks.blogspot.com/2007/10/sitemap.html"&gt;TestingRocks&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486091826623887572-1823883263858917633?l=randomtechpuzzles.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://randomtechpuzzles.blogspot.com/feeds/1823883263858917633/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8486091826623887572&amp;postID=1823883263858917633' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/1823883263858917633'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/1823883263858917633'/><link rel='alternate' type='text/html' href='http://randomtechpuzzles.blogspot.com/2007/07/sitemap.html' title='SiteMap'/><author><name>eng6537</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8486091826623887572.post-2510327636838979059</id><published>2007-07-17T17:40:00.000-07:00</published><updated>2007-07-17T17:48:16.768-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='adsense'/><category scheme='http://www.blogger.com/atom/ns#' term='SEO'/><category scheme='http://www.blogger.com/atom/ns#' term='Google'/><title type='text'>Getting google to crawl your site</title><content type='html'>An interesting behaviour I noticed with the google crawler. I was experimenting with the different features google analytics and adsense provides and discovered an interesting way to get the google crawler to crawl this blog - adsense.&lt;br /&gt;I posted a few blogs in this blog and a few days later, "googled" for this blog content and I got zero / zilch results. And looking through the adsense features I realised, adding adsense to my blog template might force google to crawl this blog to display relevant ads blah blah.. I added google adsense ads to this account and within a few hours my blog started showing up on google results. I think this will happed until they realise they dont make any money from the ads on my blog :). I will wait and see ;)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486091826623887572-2510327636838979059?l=randomtechpuzzles.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://randomtechpuzzles.blogspot.com/feeds/2510327636838979059/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8486091826623887572&amp;postID=2510327636838979059' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/2510327636838979059'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/2510327636838979059'/><link rel='alternate' type='text/html' href='http://randomtechpuzzles.blogspot.com/2007/07/getting-google-to-crawl-your-site.html' title='Getting google to crawl your site'/><author><name>eng6537</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8486091826623887572.post-1994572349085836142</id><published>2007-07-17T17:29:00.000-07:00</published><updated>2007-07-17T17:38:25.121-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='search engine companies'/><category scheme='http://www.blogger.com/atom/ns#' term='interview questions'/><title type='text'>Anagram - Generate all possible dictionary words from a given word</title><content type='html'>A contributed question ..&lt;br /&gt;Generate all possible anagrams given a word.&lt;br /&gt;&lt;br /&gt;The solution:&lt;br /&gt;Create a hash dictionary (a one time operation). Which basically is a dictionay where each word is hashed to a value. The hash function must not take into accout the order in which the alpabets occur. Eg: rat and tar hash to the same value.&lt;br /&gt;Once the hash lookup dictionary is in place, take the input and generate the hash using hte same hash function. This will point to a hash bucket whcih contains the list of all possible anagrams.&lt;br /&gt;&lt;br /&gt;Running Time: constant. (Not considering generating the hash dictionary).&lt;br /&gt;&lt;br /&gt;The same technique can be used if the question is extended to give all possible words where repetitions are allowed. The hash function should now ignore repeated alphabets. ie: shoot and shot should generate the same hash.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486091826623887572-1994572349085836142?l=randomtechpuzzles.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://randomtechpuzzles.blogspot.com/feeds/1994572349085836142/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8486091826623887572&amp;postID=1994572349085836142' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/1994572349085836142'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/1994572349085836142'/><link rel='alternate' type='text/html' href='http://randomtechpuzzles.blogspot.com/2007/07/anagram-generate-all-possible.html' title='Anagram - Generate all possible dictionary words from a given word'/><author><name>eng6537</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8486091826623887572.post-188531750745697777</id><published>2007-07-14T14:12:00.000-07:00</published><updated>2007-07-17T17:39:29.564-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='search engine companies'/><category scheme='http://www.blogger.com/atom/ns#' term='interview questions'/><category scheme='http://www.blogger.com/atom/ns#' term='yahoo'/><title type='text'>Find the missing number</title><content type='html'>You are given an array of size n-1. The array contains numbers 1-n. All numbers in the array are unique. Find the missing number&lt;br /&gt;&lt;br /&gt;The solution .. add up all the numbers in the given array. The missing number is the difference between the n(n+1)/2 and the sum.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486091826623887572-188531750745697777?l=randomtechpuzzles.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://randomtechpuzzles.blogspot.com/feeds/188531750745697777/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8486091826623887572&amp;postID=188531750745697777' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/188531750745697777'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/188531750745697777'/><link rel='alternate' type='text/html' href='http://randomtechpuzzles.blogspot.com/2007/07/find-missing-number.html' title='Find the missing number'/><author><name>eng6537</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8486091826623887572.post-3303724435094993286</id><published>2007-07-14T14:04:00.000-07:00</published><updated>2007-07-14T14:10:42.034-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='interview questions'/><category scheme='http://www.blogger.com/atom/ns#' term='yahoo'/><title type='text'>Find the number of bits set in a number</title><content type='html'>Given an integer n find the number of bits set to 1 in the number.&lt;br /&gt;Solution.&lt;br /&gt;1. Split the integer into 4 bit blocks.  (n &amp; 0xf &lt;&lt; i) where i = 1to 8&lt;br /&gt;2. Pre - populate and array of size 16 whcih represent the number of bit set for the number 1-15.&lt;br /&gt;3. get the number of bits set in each of the 8 blocks and add them up :).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486091826623887572-3303724435094993286?l=randomtechpuzzles.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://randomtechpuzzles.blogspot.com/feeds/3303724435094993286/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8486091826623887572&amp;postID=3303724435094993286' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/3303724435094993286'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/3303724435094993286'/><link rel='alternate' type='text/html' href='http://randomtechpuzzles.blogspot.com/2007/07/find-number-of-bits-set-in-number.html' title='Find the number of bits set in a number'/><author><name>eng6537</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8486091826623887572.post-9192081234261980918</id><published>2007-07-14T13:56:00.000-07:00</published><updated>2007-07-14T14:04:04.412-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='interview questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Google'/><title type='text'>Probability function</title><content type='html'>This is apparently another Google interview question ..&lt;br /&gt;Write a function that take a number between 1 and n as input such that it returns true 1/n times and every other time it returns a false.&lt;br /&gt;&lt;br /&gt;My solution, the function generates a random number between 1 and n, including 1&amp;amp;n. The function will return 1 every time the generated number is 1, every other time it returns a 0.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486091826623887572-9192081234261980918?l=randomtechpuzzles.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://randomtechpuzzles.blogspot.com/feeds/9192081234261980918/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8486091826623887572&amp;postID=9192081234261980918' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/9192081234261980918'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/9192081234261980918'/><link rel='alternate' type='text/html' href='http://randomtechpuzzles.blogspot.com/2007/07/probability-function.html' title='Probability function'/><author><name>eng6537</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8486091826623887572.post-7455032280827397691</id><published>2007-07-13T14:55:00.000-07:00</published><updated>2007-07-13T15:11:32.528-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='maps'/><category scheme='http://www.blogger.com/atom/ns#' term='Ideas'/><category scheme='http://www.blogger.com/atom/ns#' term='web2.0'/><category scheme='http://www.blogger.com/atom/ns#' term='traffic'/><title type='text'>Why mobile companies should get into maps and traffic</title><content type='html'>Why mobile companies should do real time traffic analysis ? sounds wierd but the more you think of it .. why dont they do it already. I was thinking about real time traffic analysis and an interesting idea cropped up.&lt;br /&gt;What network enabled device is present in almost every car on the street radios and cell phones. We use radio waves (XM radio ) today to get real time traffic data. The XM transmitter gets this data from all sorts of sources. But the draw back is these sources are only available on the larger highways and mostly in north america and europe. The rest of the world doesnt have this technology, but what most of the remaining world has is cell phones. Cell networks cover almost every corner of the world (well all the important corners anyway). They have the ability to pinpoint any cell phone suscriber (most subscribers have this ability in most places .. think they use triangulation) and they have access to maps. Almost every car / bike has a cell phone these days.&lt;br /&gt;Combine the fact that cell phone providers have access to maps, ability to located subscribers we get real time traffic reports for almost every road in the world :). There will always be minor (?) technical difficulties in getting live traffic reports on and from cell phones, but nothing that cant be solved with a little bits of traffic prediction technologies and data aggregation.&lt;br /&gt;&lt;br /&gt;Want to share an idea.. this is my g m @ i l   :b l o g t a m m a&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486091826623887572-7455032280827397691?l=randomtechpuzzles.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://randomtechpuzzles.blogspot.com/feeds/7455032280827397691/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8486091826623887572&amp;postID=7455032280827397691' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/7455032280827397691'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/7455032280827397691'/><link rel='alternate' type='text/html' href='http://randomtechpuzzles.blogspot.com/2007/07/why-mobile-companies-should-get-into.html' title='Why mobile companies should get into maps and traffic'/><author><name>eng6537</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8486091826623887572.post-7911806082802224591</id><published>2007-07-12T08:02:00.001-07:00</published><updated>2007-07-17T23:40:21.126-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Programming techniques'/><category scheme='http://www.blogger.com/atom/ns#' term='deadlock'/><category scheme='http://www.blogger.com/atom/ns#' term='threads'/><title type='text'>Thread Deadlocks</title><content type='html'>Here's an interesting technique on deadlock avoidance. We had a pretty complex multi-threaded application running C/C++ code. As with any multi-threaded application deadlocks were a major problem. The solution, serialize access to resources. This ensures that all threads enter the critical region in a serial order avoiding deadlocks.&lt;br /&gt;&lt;br /&gt;How does it work ?&lt;br /&gt;Lets say we have three threads t1, t2 and t3 that need to access resources r1, r2, r3. We create three locks/ semaphores s1, s2, s3.  We enforce the rule that the locks must be aquired in the following order r1, r2, r3 ie. no thread can aquire r3 before r2 &amp; releasing the locks must be in the reverse order.&lt;br /&gt;&lt;br /&gt;Assuming t2 requires resources r1 r2 and r3. It first aquires the lock for r1, r2 and r3. But before t1 aquires r3 , t2 comes along, it needs resources r3 and r2. Even though the lock for r3 is available it cant aquire r3 because of the order restriction we impose. T2 waits for till t1 releases the r2 and starts processing. If we did not impose this order restriction, t2 would have aquired r3 and would be waiting for t1 to release r2. While t1 would be waiting for t2 to release r3, resulting in a deadlock.&lt;br /&gt;&lt;br /&gt;Another interesting deadlock detection technique a little simpler to program but a little less efficient. Everytime a  thread is unable to aquire a lock, it releases all its locks and calls a scheduled yeild or kills itself. Although this method works in most cases it is not really guaranteed to work at all times.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486091826623887572-7911806082802224591?l=randomtechpuzzles.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://randomtechpuzzles.blogspot.com/feeds/7911806082802224591/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8486091826623887572&amp;postID=7911806082802224591' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/7911806082802224591'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/7911806082802224591'/><link rel='alternate' type='text/html' href='http://randomtechpuzzles.blogspot.com/2007/07/thread-deadlocks.html' title='Thread Deadlocks'/><author><name>eng6537</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8486091826623887572.post-3510328339462252017</id><published>2007-07-12T07:54:00.000-07:00</published><updated>2007-07-12T08:01:41.972-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='interview questions'/><category scheme='http://www.blogger.com/atom/ns#' term='hashing'/><category scheme='http://www.blogger.com/atom/ns#' term='Google'/><title type='text'>Google Interview Questions</title><content type='html'>This was apparently a google interview question ..&lt;br /&gt;Given a list of a billion URL's, determine if any of the URL's repeat, and the number of times the URL's repeat.&lt;br /&gt;&lt;br /&gt;Think this is a typical crawler question. The best solution I can think of is hashing.&lt;br /&gt;Hash a each URL and check the hash bucket to see if any of the URL's repeat and keep track of the counter.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486091826623887572-3510328339462252017?l=randomtechpuzzles.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://randomtechpuzzles.blogspot.com/feeds/3510328339462252017/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8486091826623887572&amp;postID=3510328339462252017' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/3510328339462252017'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/3510328339462252017'/><link rel='alternate' type='text/html' href='http://randomtechpuzzles.blogspot.com/2007/07/google-interview-questions.html' title='Google Interview Questions'/><author><name>eng6537</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8486091826623887572.post-1200718633042984063</id><published>2007-07-09T23:36:00.000-07:00</published><updated>2007-07-20T17:50:36.381-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='interview questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Facebook'/><category scheme='http://www.blogger.com/atom/ns#' term='puzzles'/><title type='text'>Facebook puzzle GridFlip - the problem</title><content type='html'>The facebook gridflip puzzle :&lt;br /&gt;The puzzle goes like this .. you are given and mxn matrix consisting of integers. Two operations are permitted on the matrix, flip_row and flip_colomn.&lt;br /&gt;Flip_row(x) -&gt; Flips the sign of all numbers in the row&lt;br /&gt;Flip_colomns(x) -&gt; Flips the sign of all numbers in the colomn.&lt;br /&gt;&lt;br /&gt;Need to calculate the smallest S with the minimun set of row / colomn operatiosn, where S is defined as the sum of SR(1-m) and SC(1-n).&lt;br /&gt;SR(x) - is defined as the sum of all numbers in row x&lt;br /&gt;SC(x) - is defined as the sum of all numbers in colomn x&lt;br /&gt;Additionally SR(x) for all x=1-m should be posotive &amp; SC(x) for x=1-n should be positive &amp;amp;&lt;br /&gt;&lt;br /&gt;The actual puzzle is available &lt;a href="http://www.facebook.com/jobs_puzzles/"&gt;here&lt;/a&gt;&lt;br /&gt;The solution to this puzzle is available&lt;a href="http://randomtechpuzzles.blogspot.com/2007/07/facebook-puzzles.html"&gt; here &lt;/a&gt;..&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486091826623887572-1200718633042984063?l=randomtechpuzzles.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://randomtechpuzzles.blogspot.com/feeds/1200718633042984063/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8486091826623887572&amp;postID=1200718633042984063' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/1200718633042984063'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/1200718633042984063'/><link rel='alternate' type='text/html' href='http://randomtechpuzzles.blogspot.com/2007/07/facebook-puzzle-gridflip-problem.html' title='Facebook puzzle GridFlip - the problem'/><author><name>eng6537</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8486091826623887572.post-2870006249076821562</id><published>2007-07-09T01:04:00.000-07:00</published><updated>2007-07-20T18:46:43.659-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='interview questions'/><category scheme='http://www.blogger.com/atom/ns#' term='Facebook'/><category scheme='http://www.blogger.com/atom/ns#' term='puzzles'/><title type='text'>Facebook GridFlip - The solution</title><content type='html'>Here's a solution to the facebook GridFlip puzzle. To get to the actual puzzle, navigate to GridFlip from &lt;a href="http://www.facebook.com/jobs_puzzles/"&gt;here&lt;/a&gt;. Incase the puzzle has been deleted a copy of the puzzle is available here.&lt;br /&gt;&lt;br /&gt;Before I start on the solution to the puzzle, here are a couple of rules / properties of the flip_row (R(x) ) and flip_colomns (C(x)) operation.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;The order of the operations doesnt matter. eg: R(1) C(1) = C(1) R(1) &lt;/li&gt;&lt;li&gt;Repeated operations cancel each other. eg: R(1) R(2) C(1) R(1) = R(2) C(1)&lt;/li&gt;&lt;li&gt;Every operation has an "inverse" which is euqual to the operation itself. eg: for a 3x3 matrix, the following operations are valid R(0) R(1) R(2) and C(0) C(1) C(2). The following operations are equal R(0) R(1) C(2) = R(2) C(1) C(2). Ie the "inverse" of an operation and an operation are equal. &lt;/li&gt;&lt;li&gt;The row sum (SR(x) ) and colomn sum (SC(x)) is effected by the following operations: SR(x) is influenced by all colomn operations and just one row operation R(x). eg: SR(x) would not change if any row operation other than R(x) is applied on the input. This is similar for the SC(x). &lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Rules on the solution. &lt;/p&gt;&lt;ol&gt;&lt;li&gt;Sum of each row SR(x) and sum of each colomn SC(x) should be non-negative. &lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Here's the solution to the GridFlip puzzle based on the above rules.. &lt;/p&gt;&lt;ol&gt;&lt;li&gt;Create an array with all possible colomn operations. Set the row operations to false. This array would have 2^n rows where n is the number of colomns in the input matrix. Eg: The operations would be C(0), C(1), C(0) C(1), ... &lt;/li&gt;&lt;li&gt;Apply each operation on each row. If after applying an operation on row x SR(x) is negative, edit the operation and set R(x) for the operation. Apply R(x) when SR(x) is negative flips the signs for all values in the row and SR(x) will become positive. &lt;li&gt;If R(x) is zero. These rows need to addressed seperately as this row will always be non-negative, but the row operation will effect C(1..n). &lt;li&gt;We now have a matrix of moves where all SR(x) is positive. &lt;/li&gt;&lt;li&gt;Apply the edited moves and calulate the SC(x) for each move. If SC(x) is negative the move is invalid. If both SC(x) is positive, calculate the array total S = SR(x) and SC(x). &lt;/li&gt;&lt;li&gt;Keep track of the smallest S to print the answer. &lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;C++ code comming soon ..... &lt;/p&gt;&lt;p&gt;The c++ code is located &lt;a href="http://blogtamma.googlepages.com/GridFlip.zip"&gt;here&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;Code license: Code is provided as-is .. no implied guarantess. You can pretty much do whatever you want with it. Just dont sue me if something goes wrong. &lt;/p&gt;&lt;p&gt;About the code .. I am a C++ newbie, this is one of my first programs in C++ and the first one using stl. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486091826623887572-2870006249076821562?l=randomtechpuzzles.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://randomtechpuzzles.blogspot.com/feeds/2870006249076821562/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8486091826623887572&amp;postID=2870006249076821562' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/2870006249076821562'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8486091826623887572/posts/default/2870006249076821562'/><link rel='alternate' type='text/html' href='http://randomtechpuzzles.blogspot.com/2007/07/facebook-puzzles.html' title='Facebook GridFlip - The solution'/><author><name>eng6537</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
