Myth
BAN USERFOSS Enthusiast!
- 1of 3 votes
AnswersI was asked this question during campus placement drive :
- Myth in United States
You have a Timer which goes to from a certain range ( n to 0), where n is not fixed and we can have it as much as we want.
The timer when goes to 0 an associated callback for the request is done.
We have multiple requests coming into the system, however the Timer is insufficient to deal with them at all at once ( it can deal with a figure less than number of requests).
How do you reuse the timer and handle all asynchronous requests?| Report Duplicate | Flag | PURGE
Microsoft Intern
- 0 Answers Gas Station Problem
We have a car that can travel distance D on the full tank, and a route of length L, with gas stations numbered 1 to n, and station i is in distance di from the start, d1 = 0. The gas at station i has price pi, which means that travelling one unit of distance with the gas purchased at that station has the cost of pi.
- Myth September 28, 2013
We need to decide at which stations to stop (including station 1 where we are stopped at the beginning) at how much gas to purchase at those station, so the cost of reaching the end of the route will be minimal.| Flag | PURGE
/*
Returns 0 for equal
Returns 1 if ch>ch2
Returns -1 if ch<ch2
*/
int rule(char ch,char ch2)
{
char arr[]={d,f,b,c,a,e};
int c=0,c1=0;
if(ch==ch2)
return 0;
for(c=0;c<arr.length;c++)
{
if(ch==arr[c])
break;
}
for(c1=0;c1<arr.length;c1++)
{
if(ch2==arr[c1])
break;
}
if(c<c1)
return -1;
else
return 1;
}
using this routine we can build up any sorting algorithm preferrably like quicksort.
- Myth February 12, 2011for(c=0;c<str.length();c++)
{
String p1= str.subString(0,c+1); //First index inclusive second exclusive
String p2=str.subString(c+1,str.length());
boolean b1=binarySearch(p1); //The dictionary file is sorted by alphabet
boolean b2=binarySearch(p2);
if(b1==true && b2==true)
print p1 and p2
}
For the String, going character by character dividing string into two parts and checking both the occurences with the dictionary using binary search.
Complexity looks in the order of o(m logn)
A linear time solution is easy. What complexity class was the interviewer looking for?
- Myth September 23, 2013