Tag Archive for facebook

Twitter and Facebook… Apples and Oranges, How Can You Compare?

With Twitters IPO looming around the corner, analysts and financial experts won’t quit referring back and forth to Facebooks IPO and comparing the two companies. Unfortunately, those that make the comparison don’t seem to understand or care that the two companies even at the most basic fundamentals are completely different.

fe74a65e7b605bf6f4a14173023726c81 As one of the most expected IPOs of the year, Twitter has been the center of attention in the financial world, and everyone wants to get a piece of the reporting action, including myself apparently. One thing that’s important to note is that I am not a professional reporter, but as someone with a bit of common sense I understand that the media loves stirring things up, making comparisons without real sense beyond trying to attracts peoples curiosity, since after all, the circus around the Facebook IPO can and will be used for years to attempt to gain ratings. But the bottom line (from a Computer Scientist and technology expert) is that comparing Facebook to Twitter is the same as comparing apples to oranges.

Read more

Facebook Hacker Cup 2013 Qualifying round

Facebooks yearly Hacker Cup started last weekend with its qualifying round running through the weekend… 3 questions, nothing TOO complicated, solve one and you’re in for round 1 which is February 2nd. I managed to squeeze my way into the 1st round by solving only the 1st question… unfortunately I didn’t read the instructions and downloaded the test file for the 2nd question which then triggered a timer of 6 minutes to submit the source code and answers… and I had neither… The third question was a pain, didn’t bother with it too much (2 tests to study for). So here’s the 1st question AND my code for it… I actually ranked 6915 out of 10169… lol.

Question 1: Beautiful Strings

When John was a little kid he didn’t have much to do. There was no internet, no Facebook, and no programs to hack on. So he did the only thing he could… he evaluated the beauty of strings in a quest to discover the most beautiful string in the world.

Given a string s, little Johnny defined the beauty of the string as the sum of the beauty of the letters in it.

The beauty of each letter is an integer between 1 and 26, inclusive, and no two letters have the same beauty. Johnny doesn’t care about whether letters are uppercase or lowercase, so that doesn’t affect the beauty of a letter. (Uppercase ‘F’ is exactly as beautiful as lowercase ‘f’, for example.)

You’re a student writing a report on the youth of this famous hacker. You found the string that Johnny considered most beautiful. What is the maximum possible beauty of this string?

Input

The input file consists of a single integer m followed by m lines.

Output

Your output should consist of, for each test case, a line containing the string “Case #xy” where x is the case number (with 1 being the first case in the input file, 2 being the second, etc.) and y is the maximum beauty for that test case.

Example Input:

5
ABbCcc
Good luck in the Facebook Hacker Cup this year!
Ignore punctuation, please :)
Sometimes test cases are hard to make up.
So I just go consult Professor Dalves

Example Output:

Case #1: 152
Case #2: 754
Case #3: 491
Case #4: 729
Case #5: 646

My solution… again, can be cleaned up, save a couple of lines… but meh.

import java.util.Scanner;

public class BeautifulStrings {

    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        final int[] chars = new int[26];
        int tempMax = 0;
        int tempMaxIndex = 0;
        int finalAnswer = 0;
        final int cases = Integer.parseInt(scn.nextLine());
        for (int i = 0; i <= cases; i++) {
            int HighestValueAvailable = 26;
            final String tempS = scn.nextLine().toLowerCase(); //temporary string converted into lower case only
            final char[] temp = tempS.toCharArray();
            for (int j = 0; j < tempS.length(); j++) {
                final int currentChar = (int) temp[j];
                if (currentChar >= 97 && currentChar <= 122) { // ensure the characters are letters.
                    chars[currentChar - 97]++;
                }
            }
            for (int a = 0; a < tempS.length(); a++) {
                for (int b = 0; b < chars.length; b++) {
                    if (chars[b] > tempMax) { // find the number that re-appears the most.
                        tempMax = chars[b]; //keep the value, and index of the value.
                        tempMaxIndex = b;
                    }
                }
                finalAnswer = finalAnswer + (HighestValueAvailable * tempMax); // calculate answer and restart variables.
                chars[tempMaxIndex] = 0;
                HighestValueAvailable--;
                tempMax = 0;
            }
            System.out.printf("Case #%d: %dn", i + 1, finalAnswer);
            finalAnswer = 0;
        }
    }
}