Tuesday, November 15, 2011
Monday, October 31, 2011
An array is given consisting of real integers , can hav repeatative elements , Now u need to find K partitions whose union will hav all the elements of the array , but the intersection of any pair of cannot hav K elements in common.
Example:-
Array- 1 1 2 2 3 1 4 3 5
For K=3 the partition are :-
(1 2 3) (1 5 2) (1 4 3)
cann't be :- (1 2 3)(3 1 2)(1 4 5)
Array- 1 1 2 2 3 1 4 3 5
For K=3 the partition are :-
(1 2 3) (1 5 2) (1 4 3)
cann't be :- (1 2 3)(3 1 2)(1 4 5)
Suppose u have a square matrix, where every cell is filled with 0 or 1 . U need to find the maximum subsquare such that all four borders are filled with all 1s.
Ex:-
1 0 0 1 1 0
1 0 1 1 1 0
0 0 1 0 1 1
0 1 1 1 1 0
1 0 0 1 1 1
Here the maximum square (3X3) possible is from the TOP LEFT (2 3) TO
BOTTOM RIGHT (4 5) .
1 0 0 1 1 0
1 0 1 1 1 0
0 0 1 0 1 1
0 1 1 1 1 0
1 0 0 1 1 1
Here the maximum square (3X3) possible is from the TOP LEFT (2 3) TO
BOTTOM RIGHT (4 5) .
Thursday, October 20, 2011
Given two bst, print the output that would come if two bsts are merged and then an inorder traversal is performed. Of, course you can't merge trees here.
PS:Heard From One of The My Friend :
Labels:Data
Amazon Interview
,
Google Interview
Given an integer N, there are 2^N binary codewords of length N. All of them are taken and sorted to create a sequence: Sort by the number of 1-bits in the codeword bit-string. If there is a tie, break tie so that the smaller number comes first in the output sequence
Example and Testcases :You would be given 2 integers N (<=10) and K (1 <= K <= 2^N)
Output the codeword with index K into this sequence
The input is from stdin and output to stdout
Sample Testcases:
Input #00:
3 5
Output #00:
011
Explanation:
For N = 3, the sequence consists of {000,001,010,100,011,101,110,
Output the codeword with index K into this sequence
The input is from stdin and output to stdout
Sample Testcases:
Input #00:
3 5
Output #00:
011
Explanation:
For N = 3, the sequence consists of {000,001,010,100,011,101,110,
111}. The 5th indexed number would be 011
Input #01:
7 127
Output #01:
1111110
Input #01:
7 127
Output #01:
1111110
Labels:Data
Facebook Interview
An array of integers is given and you have to find the largest possible integer by concatenating all elements:
Example:
array: 87 36 52
answer: 875236
array: 87 9 52
answer: 98752
|
Provide an efficient algorithm to solve the question "Can I buy N items?
A shop sells an item in packets of 6, 9, and 17. A customer can buy any number of packets, but a packet cannot be broken up. Provide an efficient algorithm to solve the question "Can I buy N items?". For example, is it possible to buy 29 items? What about 19? Your algorithm simply needs to return true or false.
Labels:Data
Coin Change
,
DirectI Interview
,
Dynamic Programming
,
Facebook Interview
,
Google Interview
,
Knapsack
Design Data Structure For Students-Courses Realtionship
In a university, students can enroll in different courses. A student may enroll for more than one course. Both students and courses can be identified by IDs given to them. Design a data structure to store students, courses, and the student-course relationships. You can use arrays, lists, stacks, trees, graphs, etc. or come up with your own data structures. Give the running times, in Big O notation, for the following operations for your data structure and justify the answers: a) Return all students in a list. b) Return all courses in a list. c) Return all courses in a list for a given student. d) Return all students in a list for a given course.
Labels:Data
Amazon Interview
,
Data Structures
,
DirectI Interview
,
Facebook Interview
,
Google Interview
Thursday, October 13, 2011
Determine a user’s influence on the system by determining how many users he is responsible for
You Know Invitation Based System. on Google+, Gmail,Yahoo,Facebook etc...users can add their friends by emailing a . We want to determine a user’s influence on the system by determining how many users he is responsible for. A user’s influence is calculated by giving him 1 point for every user he’s added in addition to the sum of the influence scores of each user that he’s added.
Example: User 0 adds User 1 and User 2. User 1 adds User 3.
User 0’s influence score is 3. (He added two users and one of them added added a third user.)
User 1's is 1.
User 2’s is 0.
User 3’s is 0.
P.S.:One of The Question Asked By Google M.V. From Me. :)
User 1's is 1.
User 2’s is 0.
User 3’s is 0.
P.S.:One of The Question Asked By Google M.V. From Me. :)
The above scenario is represented by the following input file. Line i is user ID i and position j within the line is marked with an X if user ID iadded user ID j. Both row and column indicies are 0-based:
OXXO OOOX OOOO OOOO
Subscribe to:
Posts
(
Atom
)