DashDash
BAN USER- -2of 2 votes
AnswersHow to print a variable 1000 times without using loops and recurssion
- DashDash in India| Report Duplicate | Flag | PURGE
Software Engineer / Developer - 0of 0 votes
AnswersWe have
- DashDash in India for Development
char *p = "abc";
I know we cant do p[0] = 'a'. What is the reason behind it?| Report Duplicate | Flag | PURGE
Software Engineer / Developer C++ - 0of 0 votes
AnswersWhat is the next number in the series
- DashDash in India
2,4,8,16,24...| Report Duplicate | Flag | PURGE
Goldman Sachs Applications Developer Brain Teasers - 0of 0 votes
Answersvoid copystring(char* dest, char *source)
- DashDash
{
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...| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer C++
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
The problem bogs down to design a data structure wherein
1) A time stamp can map multiple URLs i.e Multiple URLs can be opened in a particular time stamp
2) A single URL map to multiple timestamps i.e A single URL can be opened at multiple timestamps.
This is what I have deduced. Can someone please let me know what can be used in such a situaltion (many to many relationship)
int ShortestPath(int **mat, int m, int n, int currposx, int currposy)
{
if(currposx < 0 || currposy < 0 || cussposx >= m || currposy >= n)
return;
if(currposx == m-1 || cussposy == n-1 || currposx == 0 || cussposy == 0)
return mat[currposz, currposy];
else
{
return min((shortestPath(mat, m, n, currposx+1, currposy),
(shortestPath(mat, m, n, currposx-1, currposy),
(shortestPath(mat, m, n, currposx, currposy+1),
(shortestPath(mat, m, n, currposx, currposy-1)) + mat[currposx,currposy];
}
}
Please let me know if I am doing something wrong here
The Stack consists of the list of runways. I will have 2 stacks one for long runways and other for short runways. Whenever an aircraft comes we will pop a runway from the stack depending upon the size requirement and when the aircraft leaves runway we will push into a stack
- DashDash April 23, 2013class terminal
{
}
Terminal will have multiple objects of Runway
class Runway
{
string type;
Ctime t // class which holdsTime occupied
}
class Aircraft
{
}
class <NameOfAircraft> : Aircraft
{
}
In the main program I can stacks depending on the size of runways.
1 stack for small runways and second for long runways
Depending on the type of aircraft and runway runway is allocated and that stack is popped. Once it gets freed, stack gets pushed
Here is what I am doing.
Passing a comb pointer which is initially initialized to memory equivalent to 4.
Now passing this comb to the function which will print all the combinations.
Please let me know if I am doing anything wrong here
void Combinations(int sum, int *arr, int n, int ctr, int *comb, int len)
{
if(n == 0)
return 0;
if(sum == 0 && ctr == 4)
{
Print(comb, len);
return 0;
}
if(arr[n] > sum)
Combinations(sum, arr, n-1, comb, len)
else
{
comb[len] = arr[n];
Combinations(sum - arr[n], n-1, ctr+1, comb, len+1);
Combinations(sum, n-1, comb, len);
]
}
A knight can move in 8 directions from the current position
2 in front, 4 sideways and 2 backwards.
Thus we can easily calculate the position using recursion from the current position where a knight can move.
Here is a algo that I have thought
void KnightMove(int **a, int m, int n, int currx, curry)
{
if(currx<0 || curry <0)
return;
if(currx >= n || curry >=m)
return;
if(a[currx][curry] == VISITED)
return;
else
{
a[currx][curry] == VISITED;
//move forward
KnightMove(a, m, n, currx-1, curry+2);
KnightMove(a, m, n, currx+1, curry+2);
//move sideways
KnightMove(a, m, n, currx-2, curry+1);
KnightMove(a, m, n, currx-2, curry-1);
KnightMove(a, m, n, currx+2, curry+1);
KnightMove(a, m, n, currx+2, curry-1);
//move backward
KnightMove(a, m, n, currx-1, curry-2);
KnightMove(a, m, n, currx+1, curry-2);
}
}
Please do let me know If I am missing something here
we can create a max heap of songs where in the heap is arranged as per the count of the song.
Or
if we need only the song which is played max times then we can have a hash of songs where song can be the key and contains count as value. we also have a max variable which contains the max count of a song at that time. When we encounter a song we increase the count of the song by one and update the max if the count is more than max
Please let me know if something is wrong here
- DashDash May 10, 2013bool 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));
}
}