flexaired.blogspot.com
Algo Ramblings: February 2013
http://flexaired.blogspot.com/2013_02_01_archive.html
An illustration of Algorithms, Data Structures, Coding, Puzzles and a whole lot of other things. Monday, February 18, 2013. How to detect duplicate documents in billions of urls. Question: You have a billion urls, where each is a huge page. How do you detect the duplicate documents? If the two documents have exactly the same links inside the page. They have the same title. Their creation time are the same. Based on the above two observations we can derive an algorithm which is as follows:. What do we do?
flexaired.blogspot.com
Algo Ramblings: October 2011
http://flexaired.blogspot.com/2011_10_01_archive.html
An illustration of Algorithms, Data Structures, Coding, Puzzles and a whole lot of other things. Sunday, October 16, 2011. Merging sorted 1st half and 2nd half. Q: Given an integer array of which both first half and second half are sorted. Write a function to merge the two parts to create one single sorted array in place [do not use any extra space]. e.g. If input array is [1,3,6,8,-5,-2,3,8] It should be converted to: [-5,-2,1,3,3,6,8,8]. We need to keep the arrays sorted while we doing the swaps. Tried...
flexaired.blogspot.com
Algo Ramblings: Shuffle a deck of 52 cards and shuffle them equally to 4 players.
http://flexaired.blogspot.com/2013/09/shuffle-deck-of-52-cards-and-shuffle.html
An illustration of Algorithms, Data Structures, Coding, Puzzles and a whole lot of other things. Wednesday, September 11, 2013. Shuffle a deck of 52 cards and shuffle them equally to 4 players. Import java.util.ArrayList;. Import java.util.HashMap;. Import java.util.List;. Import java.util.Map;. Import java.util.Random;. Import java.util.Set;. Write the code to shuffle a deck of 52 cards,. And shuffle them equally to 4 players. Public enum Rank {. Public enum Suit {. CLUBS, DIAMONDS, HEARTS, SPADES.
flexaired.blogspot.com
Algo Ramblings: June 2013
http://flexaired.blogspot.com/2013_06_01_archive.html
An illustration of Algorithms, Data Structures, Coding, Puzzles and a whole lot of other things. Tuesday, June 4, 2013. Longest substring with 2 unique characters. Q: Find the longest substring with at most two unique characters(ASCII) in a given string . Import java.util.Arrays;. Public class Problem {. Public static String longestTwoUnique(String s) {. Char str[] = s.toCharArray();. Int[] set = new int[256];. Arrays.fill(set, -1);. String res = ;. Int count = 0;. While (j s.length() {. Set[str[j] = j;.
flexaired.blogspot.com
Algo Ramblings: Minimum Sum of the given array.
http://flexaired.blogspot.com/2013/08/minimum-sum-of-given-array.html
An illustration of Algorithms, Data Structures, Coding, Puzzles and a whole lot of other things. Monday, August 26, 2013. Minimum Sum of the given array. You have given an array of Integer. You can change the sign of any element of the array. Write a program-me to find minimum sum of the given array. For Example: 2 1 3 4 2. Minimum sum = 0 if -2, -1, -3 , 4, 2. Public class MinimumSum {. Public static boolean calculate(int arr[], int tot, int totalSum). Int n = arr.length;. For(int i = 0; i n; i ).
flexaired.blogspot.com
Algo Ramblings: August 2013
http://flexaired.blogspot.com/2013_08_01_archive.html
An illustration of Algorithms, Data Structures, Coding, Puzzles and a whole lot of other things. Monday, August 26, 2013. Minimum Sum of the given array. You have given an array of Integer. You can change the sign of any element of the array. Write a program-me to find minimum sum of the given array. For Example: 2 1 3 4 2. Minimum sum = 0 if -2, -1, -3 , 4, 2. Public class MinimumSum {. Public static boolean calculate(int arr[], int tot, int totalSum). Int n = arr.length;. For(int i = 0; i n; i ).
flexaired.blogspot.com
Algo Ramblings: Longest palindrome in a string
http://flexaired.blogspot.com/2013/09/longest-palindrome-in-string.html
An illustration of Algorithms, Data Structures, Coding, Puzzles and a whole lot of other things. Wednesday, September 11, 2013. Longest palindrome in a string. The best approach is that from the mid of any palindrome, if we go to right and left by 1 place, it’s always same character. For example 12321, here mid is 3 and if we keep moving one position in both sides, we get 2 and then 1. We will use the same logic in our java program to find out the longest palindrome. Public class LongestPalindromeFinder {.
flexaired.blogspot.com
Algo Ramblings: Concurrent LRU Cache
http://flexaired.blogspot.com/2013/09/concurrent-lru-cache.html
An illustration of Algorithms, Data Structures, Coding, Puzzles and a whole lot of other things. Monday, September 9, 2013. Public class ConcurrentLRUCache Key, Value {. Private final int maxSize;. Private ConcurrentHashMap Key, Value map;. Private ConcurrentLinkedQueue Key queue;. Public ConcurrentLRUCache(final int maxSize) {. ThismaxSize = maxSize;. Map = new ConcurrentHashMap Key, Value (maxSize);. Queue = new ConcurrentLinkedQueue Key ();. Param key - may not be null! Param value - may not be null!
flexaired.blogspot.com
Algo Ramblings: September 2013
http://flexaired.blogspot.com/2013_09_01_archive.html
An illustration of Algorithms, Data Structures, Coding, Puzzles and a whole lot of other things. Wednesday, September 11, 2013. Shuffle a deck of 52 cards and shuffle them equally to 4 players. Import java.util.ArrayList;. Import java.util.HashMap;. Import java.util.List;. Import java.util.Map;. Import java.util.Random;. Import java.util.Set;. Write the code to shuffle a deck of 52 cards,. And shuffle them equally to 4 players. Public enum Rank {. Public enum Suit {. CLUBS, DIAMONDS, HEARTS, SPADES.