Wednesday, October 22, 2014

Inbox From Google: Review

In an another attempt to reorganise the way email communications work Google has come out with Inbox.


Here, google has attempted to use machine learning and nlp for better organise email with a more intuitive UX.

I believe this time they have utilised there learnings from Wave failure and have not attempted to change the core email component. But as people are slowly getting use to the timeline kind of UX, they have attempted to preserve that in email and top it up with the new features which they have always wanted to try but restricted by the plain UX of email, like "See pull request", "See flight status."
Moreover, seems like this being designed specifically for phone devices.

Lets see how useful this cool thing becomes. Never the less, please request an invite by sending a mail to inbox@google.com.

I have requested mine and write a review as soon as I get an invite.

I got an invite and have started using Inbox. I did not find it majorly innovative.  There was nothing which was apparent to me that I was not able to do with the current version of Gmail. So, I would get straight to listing down the pros and cons.



Pros:

  • Easy to use UI, quickly can organise mails.
  • Nice timeline view.
Cons:
  • No feature which I can't already do with Gmail.
  • Just a sexy UI.

I have just used it for a few days. But this is an honest feeling I got. I might still have to explore more to realise some new features but on the look of things I was disappointed.

Leave a comment with your email id if you need an invite.
Request others to share there invites with the people commented.

Workaround to get in without invite:

Install inbox on your android phone. Then ask a friend who has an invite to login and use inbox app for 5 minutes. Then ask him to log out and you log in. Hurray!! google inbox would remain active for you.

Tuesday, October 14, 2014

Flatten a Binary Search Tree into a LinkedList in Java

package com.biplav.algorithms;

public class FlattenBST {
 
 public static class TreeNode {
  public TreeNode left;
  public TreeNode right;
  public int value;
  public TreeNode(TreeNode left, TreeNode right, int value) {
   super();
   this.left = left;
   this.right = right;
   this.value = value;
  }
  
 }
 
 public static class ListNode {
  public ListNode next;
  public int value;
  public ListNode(ListNode next, int value) {
   super();
   this.next = next;
   this.value = value;
  }  
 }
 
 public static ListNode flatten(TreeNode root) {
  ListNode left = root.left != null ? flatten(root.left) : null;
  ListNode base = new ListNode(null,root.value);
  ListNode right = root.right != null ? flatten(root.right) : null; 
  base.next = right != null ? right : null;
  if(left == null) return base;
  else {
   ListNode home = left;
   while(left.next != null) left = left.next;
   left.next= base;
   return home;
  }
 }
 /*
  *          6
  *      3       8
  *   2    4   7  10
  */
 
 public static void main(String[] args) {
  TreeNode t3 = new TreeNode(null, null, 2);
  TreeNode t2 = new TreeNode(null, null, 4);
  TreeNode t4 = new TreeNode(t3, t2, 3);
  TreeNode t7 = new TreeNode(null, null, 7);
  TreeNode t10 = new TreeNode(null, null, 10);
  TreeNode t8 = new TreeNode(t7, t10, 8);
  TreeNode t6 = new TreeNode(t4, t8, 6);
  ListNode root = flatten(t6);
  while(root != null) {
   System.out.println(root.value);
   root = root.next;
  }
 }
 
 

}

Monday, October 13, 2014

Alogrithm to sort a huge list of numbers in O(n) complexity in Java

A large file of numbers can be sorted in O(n) complexity by using a large bit array of the size same as the largest number in the list of numbers to be sorted. It can be done in Java using BitSet.


package com.biplav.algorithms;

import java.util.Arrays;

import com.biplav.ds.BitArray;


public class SortMillionNumbersWithGivenMax { //n+m


public static int[] sort(int[] list, int max) {
int[] sortedList = new int[list.length];
//BitSet bitSet = new BitSet(max);
BitArray bitSet = new BitArray(max);
for(int n:list) bitSet.set(n); //n
int index=0;
for(int i =0 ; i<=  max; i++) { //m
if(bitSet.get(i)) {
sortedList[index++] = i;
}
}
return sortedList;
}

public static void main(String[] args) {
int[] list = new int[]{1,2,3,4,5,9,15,18,25,7,11};
System.out.println(Arrays.toString(sort(list, 27)));
}
}

I have used BitArray defined by me. Its implementation is:

package com.biplav.ds;

public class BitArray {
 private byte[] arrayOfSize8bit;

 public BitArray(int size) {
  arrayOfSize8bit = new byte[(size / 8) + (size % 8 == 0 ? 0 : 1)];
 }

 public boolean get(int location) {
  return (arrayOfSize8bit[location / 8] & 1 << location % 8) != 0;
 }

 public void set(int location, boolean value) {
  byte b8 = arrayOfSize8bit[location / 8];
  byte posBit = (byte) (1 << (location % 8));
  if (value) {
   b8 = (byte) (b8 | posBit);
  } else {
   b8 = (byte) (b8 & (255 - posBit));
  }
  arrayOfSize8bit[location / 8] = b8;
 }

 public void set(int location) {
  set(location, true);
 }

 public void unset(int location) {
  set(location, false);
 }
}

Instead of BitArray BitSet can also be used which uses long[] instead of Byte array to achieve something similar.

Friday, October 10, 2014

Fibonacci Series With Matrix Multiplication in Java with recursion.

Attempting to solve the fibonacci series using matrix multiplication applying divide and conquer to reduce the complexity to O(logN)
package com.biplav.algorithms;
public class FibonacciSeries {
//2*2 matrix
static int[][] multiply(int[][] X, int[][] Y) {
int[][] response = new int[2][2];
response[0][0] = X[0][0]*Y[0][0] + X[0][1]*Y[1][0];
response[0][1] = X[0][0]*Y[0][1] + X[0][1]*Y[1][1];
response[1][0] = X[1][0]*Y[0][0] + X[1][1]*Y[1][0];
response[1][1] = X[1][0]*Y[0][1] + X[1][1]*Y[1][1];
return response;}
static int[][] power(int[][] X, int N) {
if(N == 1) {
return X;} else {
int[][] X2 = power(X,N/2);
return multiply(X2,X2);
}
}
public static int get(int n) {int[][] X = new int[][] {{1,1},{1,0}};
return power(X,n)[0][0];
}
public static void main(String[] args) {
System.out.println(get(4));
}
}

Tuesday, October 7, 2014

Attendance.gov.in is First Modern looking site by Indian Government

The http://attendance.gov.in/ is by far one of the first modern looking website by Indian Government.


It uses bootstrap and Free bootstrap 2 theme sb-admin http://startbootstrap.com/template-overviews/sb-admin/


Impressed by this sudden technology choices shift in the Indian Government websites, I decided to deep dive more on there technology stack and it was good to see there choices are improving.
See the builtwith result here: http://builtwith.com/attendance.gov.in

Suprising there is no hint of the organisation created the site. But, I am happy to see the first mobile ready website of Indian Govt! :)




Flipkart Apology Email for bloopers on The Big Billion Day Sale.

Here is the email which flipkart sent today apologising for bloopers on The Big Billion Day Sale.

Apologies, from Flipkart

regarding The Big Billion DayUnsubscribe

Flipkart.com
Download Flipkart AppFlipkart First

Dear Customer, 

Yesterday was a big day for us. And we really wanted it to be a great day for you. But at the end of the day, we know that your experience was less than pleasant. We did not live up to the promises we made and for that we are really and truly sorry. 

It took enormous effort from everyone at Flipkart, many months of preparation and pushing our capabilities and systems to the limit to be able to create this day. We were looking at fulfilling the dreams of millions of Indian consumers through deals and offers we had painstakingly put together for months. 

And though we saw unprecedented interest in our products and traffic like never before, we also realized that we were not adequately prepared for the sheer scale of the event. We didn't source enough products and deals in advance to cater to your requirements. To add to this, the load on our server led to intermittent outages, further impacting your shopping experience on our site. 

An unprecedented 1.5 million people shopped at Flipkart yesterday. While we stand humbled by the sheer faith that such a large number of customers have shown in us, we are unhappy that we were unable to live up to the expectations of millions more who wanted to buy from us yesterday. 

And this is not acceptable to us. 

Delighting you, and every single one of our customers, is absolutely the top most priority for Flipkart and we have worked very hard over the last seven years to earn your trust. Yesterday, we failed that trust. We have learnt some valuable lessons from this and have started working doubly hard to address all the issues that cropped up during this sale. 

Price Changes As we were preparing various deals and promotional pricing in the lead up to the sale, the pricing of several products got ​changed to their non-discounted rates for a few hours​. We realise that this breaks the trust our customers have put in us. We are truly sorry for this and will ensure that this never happens again.

Out-of-stock Issues We ran out of the stock for many products within a few minutes (and in some cases, seconds) of the sale going live. For example, most of our special deals were sold out as soon as they went live. We had ensured availability, anywhere from hundreds to a few lakh units for various products, but it was nowhere near the actual demand. We promise to plan much better for future promotions and ensure that we minimise the out-of-stock issues. 

Cancellations We had large number of people buying specific products simultaneously. This led to some instances of an order getting over-booked for a product that was sold out just a few seconds ago. We are working round-the-clock to ensure availability of additional units for these products and will do our level best to ensure that we minimise any cancellations. 

Website Issues ​We realise that the shopping experience for many of you was frustrating due to errors and unavailability of the website at times. We had deployed nearly 5000 servers and had prepared for 20 times the traffic growth - but the volume of traffic at different times of the day was much higher than this. We are continuing to significantly scale up all our back end systems so that we do a much, much better job next time. 

Everything that we have achieved at Flipkart is purely on the basis of our customer's trust and faith. This is why we come to work each day and continue to remain extremely passionate about building the best possible customer experience for Indian consumers. We failed to live up to this promise yesterday and would like to apologise once again to every single customer for our failure. 

Thank you. 
Sachin and Binny