King007
BAN USER- 0of 0 votes
AnswersYou are given 3 sorted array of equal length say 'm' and another empty array of length 3m. you have to put every elements from the three sorted array to the bigger array in minimum number of comparisons such that final array will have sorted numbers from all three array. eg. A[]={2,4,6,8} B[]={1,3,5,7} C[]={10,12,14,16} final output X[]={1,2,3,4,5,6,7,8,10,12,14,16}
- King007 in India for Java| Report Duplicate | Flag | PURGE
Software Engineer / Developer Algorithm - -3of 5 votes
AnswersYou are given two eggs of same size and shape, there is a 50 stories building. you have to find the toughest egg in minimum number of attempts. Once egg is broken you won't be given a replacement.
- King007 in India for Java| Report Duplicate | Flag | PURGE
Software Engineer / Developer Brain Teasers
We can use HashMap to store the user information. Here the key will be username and value will be another hashmap like: Map<String, Map<Date, String>> userInfo = new HashMap<String, HashMap<Date,String>>();
the userInfo will map user with their activity. the innermap will store user activity for a particular day. inner map will map particular date with the unique page visit for the particular day.
at the end of the 3rd day iterate through the map for each user and check for the unique visit on a particular day.
I think this satisfies the requirement.
If we are allowed to use extra space then this problem can be solved in O(n) space and O(n) time complexity. store the memory in a list once a node is visited. on each visit check list whether it contains the memory location if not add the memory of the item else the point will be the loop point.
- King007 July 08, 2013private static int[] calculate(int[] input) {
int len = input.length, sum = 0, i = 0;
boolean flag = true;
for(i =0; i<len; i++) {
sum = sum*10 + input[i];
if(input[i] != 9) flag = false;
}
sum += 1;
if(flag){
len = len+1;
int[] returnArr = new int[len];
for(i=len-1; i >=0; i--) {
returnArr[i] = sum%10;
sum=sum/10;
}
return returnArr;
} else {
for(i=len-1; i >= 0; i--) {
input[i] = sum%10;
sum = sum/10;
}
}
return input;
}
RepSpent several months writing about boyfriend ki shadi todne ke upay .Spent 2001-2007 donating carp in Las Vegas, NV. My ...
Finding a loop in linked list single iteration:
we can use HashSet implementation of java. Below is code:
- King007 January 05, 2014