adam2008
BAN USER- 1of 1 vote
Answershow would you omplement an async task when it's not native in the programming language you're using?
- adam2008 in United States| Report Duplicate | Flag | PURGE
Apple Software Engineer / Developer - 1of 1 vote
Answersgiven sorted int[] A, int[] B. How would you find the maiden that would have been if both were combined to one big sorted array? Use divide and conqure recurssion.
- adam2008 in United States
please write method "GetMutualMaiden" and explaint it's time and space complexity| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer - 4of 4 votes
AnswersGiven an array A of N integers, we draw N discs in a 2D plane such that the I-th disc is centered on (0,I) and has a radius of A[I]. We say that the J-th disc and K-th disc intersect if J ≠ K and J-th and K-th discs have at least one common point.
- adam2008 in United States
Write a function:
int number_of_disc_intersections(int A[], int N);
that, given an array A describing N discs as explained above, returns the number of pairs of intersecting discs. For example, given N=6 and:
A[0] = 1 A[1] = 5 A[2] = 2
A[3] = 1 A[4] = 4 A[5] = 0
intersecting discs appear in eleven pairs of elements:
0 and 1,
0 and 2,
0 and 4,
1 and 2,
1 and 3,
1 and 4,
1 and 5,
2 and 3,
2 and 4,
3 and 4,
4 and 5.
so the function should return 11.
The function should return −1 if the number of intersecting pairs exceeds 10,000,000.
Assume that:
N is an integer within the range [0..10,000,000];
each element of array A is an integer within the range [0..2147483647].
Complexity:
expected worst-case time complexity is O(N*log(N));
expected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments).
Elements of input arrays can be modified.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer - 0of 0 votes
AnswersThe diameter of a tree is the number of nodes on the longest path between two leaves in the tree. The diagram below shows a tree with diameter nine, the leaves that form the ends of a longest path are shaded (note that there is more than one path in each tree of length nine, but no path longer than nine nodes).
- adam2008 in United States
In particular, note that the diameter of a tree T is the largest of the following quantities:
the diameter of T's left subtree
the diameter of T's right subtree
the longest path between leaves that goes through the root of T
Given the root node of the tree, return the diameter of the tree| Report Duplicate | Flag | PURGE
Google - 0of 0 votes
Answerswrite the most efficient (in terms of time complexity) function getNumberOfPrimes which takes in an integer N as its parameter.
- adam2008 in United States
to return the number of prime numbers that are less than N
Sample Testcases:
Input #00:
100
Output #00:
25
Input #01:
1000000
Output #01:
78498| Report Duplicate | Flag | PURGE
Google - 1of 1 vote
Answerslongest common subsequnce: given two lists, find the longest sublist (in order) that is the same
- adam2008 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer - -1of 1 vote
Answerswrite a function to sum two single linked lists that represents binaries numbers
- adam2008 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer - 7of 7 votes
AnswersWrite a function that gets a billion integers. How can you find the midian in most efficient way (time)?
- adam2008 in United States
same question, but the input is an endless stream of integers, and we want to find the current median.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer - 0of 2 votes
Answersgive examples of hash functions that maps english word to byte
- adam2008 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer
it means: we can find a hash function that maps english words to 2 byte value (the picture enables 2^ 16 different binary words, more that needed for the english language). Then a sentence is mapped to a btye[] or even long type. This is the key for the hash table. teh value is a counter. We keep aside the max counter + it's key. At any moment we can print it.
- adam2008 February 23, 2013Here is my try. Is this efficient engouh?
{{
static int getNumberOfPrimes(int N) {
if (N <= 0) return 0;
if (N < 3) return N-1;
List<int> primes = new List<int>(){2};
for (int i = 3; i < N; i++)
{
var flag = true;
foreach (var num in primes)
{
if ((i % num) == 0)
{
flag = false;
break;
}
}
if (flag)
{
primes.Add(i);
}
}
return primes.Count;
}
}}
we keep an aggregation on consecutive 1 or 0.
meaning 111000111 is <3,1> <3,0> <3,1>
1) if the first bulk is of 1's. it turns to bulk of 0`s and turn the very next 0 to 1.
we now check if we can aggregate bulks of 1's.
2) if the first bulk is of 0's, we make the first digit 1. and see if we can aggregate 1's.
Assuming we only need the two counters (last hour\minute) here is my idea:
keep a buffer of pairs in the main memory <start time, secondery memory address>. Keep aside the start and end of this buffer. Every time a new event is entered: iterrate from the start, deallocate the memory of an event which is older than 1 hour and decrement the last-hour-events by one. enter your new event at the end and increment the counter by one.
Corrections are welcome.
The q says: "1) Record an Event". why do you assume: "you do not need to store all events" ?
How would you "dynamically aggregate them for saving the space"? how long will you save? last minute? last hour?
if we want to keep all the events: we can keep in the main-memory pairs of <start,end> addresses in the secondary memory. we will open a new pair every time a non consecutive memory is allocated.
Corrections are appreciated.
are you sure your count works? at the end I'll get the total number of ways to exit the maze?
- adam2008 February 23, 2013