DashDash
- 4
0of 0 votes
AnswersWhich data structure we can use to represent many to many relationship in a memory.
- DashDash on April 25, 2013 in United States Edit | Report Duplicate | Flag
i.e A URL is opened at multiple timestamps and single timestamp can be related to multiple URLs
- 23
-1of 1 vote
AnswersHow to print a variable 1000 times without using loops and recurssion
- DashDash on April 20, 2013 in India Edit | Report Duplicate | Flag
Software Engineer / Developer - 7
0of 0 votes
AnswersThere are some exceptions that cannot be caught by try catch. How to catch such exceptions? Can we prevent our program to crash if we are not able to catch such exceptions.
- DashDash on March 26, 2013 in India Edit | Report Duplicate | Flag
Samsung Software Engineer / Developer C++ - 15
0of 0 votes
AnswersFind the sub array from an array of positive numbers where sum is maximum and numbers that are selected are not adjacent
- DashDash on October 07, 2012 in India Edit | Report Duplicate | Flag
Adobe Software Engineer / Developer Algorithm - 50
0of 0 votes
AnswersYou are given a string. You need to find the longest substring with unique characters in O(n) time
- DashDash on May 26, 2012 in India Edit | Report Duplicate | Flag
Amazon Software Engineer / Developer Algorithm - 17
0of 0 votes
AnswersWe have
- DashDash on May 16, 2012 in India for Development Edit | Report Duplicate | Flag
char *p = "abc";
I know we cant do p[0] = 'a'. What is the reason behind it?
Software Engineer / Developer C++ - 34
0of 0 votes
AnswersWhat is the next number in the series
- DashDash on May 12, 2012 in India Edit | Report Duplicate | Flag
2,4,8,16,24...
Goldman Sachs Applications Developer Brain Teasers - 16
0of 0 votes
Answersvoid copystring(char* dest, char *source)
- DashDash on September 18, 2010 Edit | Report Duplicate | Flag
{
while(*source != NULL)
{
*dest = *source;
dest++;
source++;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
char input[10] = "hello";
char *dest;
dest = &input[1];
copystring(dest, input);
return 0;
}
What is the output of the program...
Microsoft Software Engineer / Developer C++ - 19
0of 0 votes
AnswersGiven an array of size n.find 2 numbers from array whose difference is least
- DashDash on September 04, 2010 Edit | Report Duplicate | Flag
- 6
0of 0 votes
AnswersThis question is being asked in the careercup chat
- DashDash on July 24, 2010 Edit | Report Duplicate | Flag
Find 2 nodes in a BST with given sum k
Recursion is allowed but no extra space is allowed
Time complexity = O(n)
Space Complexity = O(1)
- 42
0of 0 votes
Answersgiven a matrix pxq
- DashDash on July 21, 2010 Edit | Report Duplicate | Flag
You start from top left and have to reach the bottom right. Can only traverse right or bottom
How many ways are there to reach at the bottom right?
Google Software Engineer / Developer Matrix - 1
0of 0 votes
AnswerHow do you delete the object of a singleton class?
- DashDash on July 16, 2010 Edit | Report Duplicate | Flag
Software Engineer / Developer - 8
0of 0 votes
AnswersWhich is the best data structure to hold multiple keys for multiple objects
- DashDash on July 13, 2010 Edit | Report Duplicate | Flag
ie each object have multiple keys
Software Engineer / Developer - 8
0of 0 votes
AnswersHow to find the missing K elements out of the unsorted natural N elements in an integer array.
- DashDash on July 11, 2010 Edit | Report Duplicate | Flag
Time complexity has to be O(n), with 3 extra variables of Space.
Software Engineer / Developer - 7
0of 0 votes
AnswersGiven an array of size n.find 2 numbers from array whose difference is least.
- DashDash on July 11, 2010 Edit | Report Duplicate | Flag
Software Engineer / Developer - 9
0of 0 votes
AnswersCount the number of Bits that are set in a floating point number
- DashDash on July 10, 2010 Edit | Report Duplicate | Flag
Software Engineer / Developer Algorithm
Do a level order traversal. Remember for null leaves enter blank in an array
eg
1
2 3
4 6 7
post order traversal is : 1234_67
Now here we follow the property that child will always be at 2i and 2i+1 index or vise versa parent is always at |i/2| index
therefore parent of 1 will be no one
parent of 2 = 2/2 = 1 i.e 1
parent of 3 = 3/2 = 1 i.e 1
parent of 4 = 4/2 = 2 i.e 2 and rest copy from 2
parent of 6 = 6/2 = 3 i.e 3 and rest copy from 3
parent of 7 = 7/2 = 3 i.e 3 and rest copy from 3
This can be solved using recursion
Please let me know if I have messed up somewhere here.
void FromTo(char *source, char *dest, char **stackofWords, int wordCount)
{
if(strcomp(source, dest) == 0)
{
print(stackofWords, wordcount);
return;
}
else
{
for(int i=0;i<strlen(source);i++)
{
for(int j=0;j<26;j++)
{
if((char)((int)'A' + j) != source[i])
source[i] = (char)((int)'A' + j);
else
continue;
stackofwords[wordcount] = source;
Fromto(source, dest, stackofWords, wordcount+1);
}
}
}
}
Algo
I am changing every letter with all the alphabets in the english dictionary and then comparing with the desitnation.
Here is my question
We can an array of bits. When we convert it to a integer, isn't we are scanning each and every array element? I mean
We divide the array into 2 halfes and take the first half. Now to know whether first half has a 1 we convert the array into integer.
My question is how we are converting the array into integer?Are we not scanning the complete array for this?
Do you want me to code for the solution? I think once an algorithm of a problem is known, coding may no be a problem.
Please do let me know if you are finding anything wrong with the above solution, we can discuss.
Also let me know if you want concrete code, I will write it down for you
Please let me know if something is wrong here
bool IsSumForOdd(int *arr, int n, int count, int sum)
{
if(sum == 0 && count%2 == 0)
return true;
if(sum < 0)
return false;
if(sum < arr[n-1])
return IsSumForOdd(arr, n-1, count, sum);
else
{
return (IsSumForOdd(arr, n-1, count+1, sum-arr[n-1])) || (IsSumForOdd(arr, n-1, count, sum));
}
}
Starting from any node we can calculate the diff between distance and petrol at each node.
(assuming we can only travel in one direction).
now I will start from a node which will have max positive diff and then work out going through every node. I cannot take nodes as start nodes which have negative diff.
I will have 2 types of parking here. For big cars and small cars. Small cars can be accommodated in big cars parking but not vice versa. .
Will have 2 queues for this.
Once the queue for small cars is full I will assign big cars pool or queue to small cars.
Here can be the classes
Class Garage
{
int id
}
Class SmallGarage : Garage
{
Car objId;
}
Class BigGarage : Garage
{
Car objId;
}
Will have multiple objects of smallGarage and BigGarage each inserted in a queue
As an when we have a car object we dequeue a queue and then enqueu in a queue with the car object assigned to that garage object.
Here is the modified solution. Hope this helps
bool SubArray(int n, int *arr, int N, Sum, int *val, int index) // N is the number of elements in the array
{
if(n < 0)
return false;
if(Sum \ N == 0)
{
//PrintSubArray
PrintSubArray(val, index);
}
else
{
val[index] = arr[n-1];
SubArray(n-1, arr, N, Sum + arr[n-1], val, index+1);
IsSubArray(n-1, arr, N, Sum, val, index);
}
}
bool IsSubArray(int n, int *arr, int N, Sum) // N is the number of elements in the array
{
if(n < 0)
return false;
if(Sum \ N == 0)
return true;
else
{
return (IsSubArray(n-1, arr, N, Sum + arr[n-1]) | IsSubArray(n-1, arr, N, Sum);
}
}
This fn will find whether there is any subarray like this.
We can easily modify this fn to get the elements of the subarray which has the sum divisible by N
Lets take customerId and VideoId as a key. Therefore for this key we can create a hash and where chaining is done for the same key and the data in the same key are sorted according to the time stamp. In this way we can get the difference between 2 time stamp and can predict whether a customer is facing buffering issues
Please do let me know your suggestions
WE can improve the algorithm in the controller which is controlling the elevators.
- DashDash on June 14, 2013 Edit | Flag View Reply