2012 Fight for Google positions.

66 views
Skip to first unread message

Seabook

unread,
Mar 14, 2012, 12:11:07 AM3/14/12
to happy-pr...@googlegroups.com
It's a whole new year for another round of Google position hunting.
I failed last year and hopefully we can nail it this year. If you guys have the same thought, probably we can work together and fight for Google position together.

Rough plan for Google Interview Plan this year:

1) Read Structure and Algorithm again.
2) Daily (or 2 days) Algorithm from Top Coder or somewhere else.
3) Discussion

Thanks,
Seabook

Yongmin Xia

unread,
Mar 14, 2012, 12:12:52 AM3/14/12
to happy-pr...@googlegroups.com
I am sure that I would not be able to get any position from google, but I am happy to join you guys for my learning purpose.

Cheers, Jason

Seabook

unread,
Mar 14, 2012, 12:18:04 AM3/14/12
to happy-pr...@googlegroups.com
Today's Algorithm:
1) Calculate the sum of the most occurrences number in an Positive Integer array. If the occurrences is same, pick up the largest sum.
example {1,2,3,4,5,4}  ==> there are two 4s in the array, so the result should be 8.
example {1,1,2,2,3,3,4,5,6,6} ==> two 6s is the largest sum, the result should be 12

Rules:
Can't use Java collection, you can write your own collections if you like. Try to calculate as fast as possible.

Thanks,
Seabook

Seabook

unread,
Mar 14, 2012, 12:19:03 AM3/14/12
to happy-pr...@googlegroups.com
Hey Jason, don't be so sure, probably you will make it.

Thanks,
Seabook

Seabook

unread,
Mar 18, 2012, 8:27:06 PM3/18/12
to happy-pr...@googlegroups.com
Today's algorithm
given 4 or 5 cards (A,2,3,4,5,6,7,8,9,10,J,Q,K  cards can be duplicated) and use  +/-/*/÷ to calculate, please make the result be 24

eg.  3 8 2 3  --->  3 * 8 * ( 3 - 2 ) = 24
         5 2 6 4 --->  5 * 6 - 4 - 2 = 24
         7 7 7 2 5 ---->  7 + 7 + 7 + 5 - 2 = 24

Thanks,
Seabook
Message has been deleted

Pavel Volkov

unread,
Mar 19, 2012, 8:57:20 PM3/19/12
to Data Structures Algorithms and Programming
package google;

public class MostAccurence {

private int [] arrayInp = {1,1,3, 2,2,2,2,2,4,3,2,3,2,5,6,6 };
private BinNode indexes = null;

private int iMaxIndex = 0;
private int iMaxNumber = 0;

private void addValue(BinNode node , int v)
{
if(node.value == v)
{
node.weight ++;

//replace MAX values
if(node.value * node.weight > iMaxNumber * iMaxIndex)
{
iMaxIndex = node.weight;
iMaxNumber = node.value;
}
}
else if(node.value < v)
{
if(node.rightNode == null)
{
node.rightNode = new BinNode(v, 1);
}
else
{
addValue(node.rightNode, v);
}
}
else
{
if(node.leftNode == null)
{
node.leftNode = new BinNode(v, 1);
}
else
{
addValue(node.leftNode, v);
}
}

}

public MostAccurence()
{
indexes = new BinNode(arrayInp[0], 1);

for (int i = 1; i <arrayInp.length; i++ )
{
addValue( indexes, arrayInp[i]);
}

System.out.println(iMaxNumber + " appears " + iMaxIndex + "
times");
}

public static void main(String[] args) {
new MostAccurence();

}

}

Pavel Volkov

unread,
Mar 20, 2012, 1:32:29 AM3/20/12
to Data Structures Algorithms and Programming
Hi,

Here is the solution, which gives some feasible results:

*******************************************************************************

package google;

import java.util.HashSet;
import java.util.Set;

public class Cards24 {

// { 1,2,3,4,5,6,7,8,9,10,11,12,13 }
// 1 to 13 = { A,2,3,4,5,6,7,8,9,10,J ,Q ,K }

private int [] cards = {2,4,8,12,1};
private final double RESULT = 24; //should be double for
devision
private Set <String> setCombination = new HashSet <String>();

private void permMult (int v[], int size, int i, String result,
double iRes) {

if (i == size)
if(iRes == RESULT)
{
if(setCombination.contains(result) == false)
{
setCombination.add(result);
System.out.println("RESULT : =" + result);
}
}

// printArray(v);
for (int j = i ; j<size; j++) {
swap (v, i, j);
// printArray(v);

if (i == 0)
{
permMult (v, size, i+1, "" + v[i], v[i]);
permMult (v, size, i+1, "-" + v[i], -
v[i]);
// printArray(v);
// System.out.println( v[i] );
}
else
{
permMult (v, size, i+1, "(" + result + ") + " +
v[i], iRes + v[i]);
permMult (v, size, i+1, "(" + result + ") - " +
v[i], iRes - v[i]);
permMult (v, size, i+1, "(" + result + ") / " +
v[i], iRes / v[i]);
permMult (v, size, i+1, "(" + result + ") * "
+ v[i], iRes * v[i]);
}
swap (v, i, j);
}

}

private void printArray(int [] v)
{
for(int i = 0; i < v.length; i++)
{
System.out.print(v[i] +" ");
}
System.out.print("\n");
}

void swap (int v[], int i, int j) {
int t;

t = v[i];
v[i] = v[j];
v[j] = t;
}

public Cards24()
{
permMult(cards, cards.length, 0,"", 0);
}

public static void main(String[] args) {
// TODO Auto-generated method stub
new Cards24();
}
}



*******************************************************************************
> >> Seabook- Hide quoted text -
>
> - Show quoted text -

Seabook

unread,
Mar 20, 2012, 1:35:22 AM3/20/12
to happy-pr...@googlegroups.com
Cool. Now I can write a 24 card games.

Thanks,
Seabook
Reply all
Reply to author
Forward
0 new messages