Anand Barnwal
BAN USER- 0of 0 votes
AnswersDesign "bookmyshow.com"
- Anand Barnwal in India| Report Duplicate | Flag | PURGE
Morgan Stanley design - 0of 0 votes
AnswersThis is a sample program to find the maximum contiguous sum in an array.
int maxSubArraySum(int a[], int size) { int max_so_far = a[0], i; int curr_max = a[0]; for (i = 1; i < size; i++) { curr_max = max(a[i], curr_max+a[i]); max_so_far = max(max_so_far, curr_max); } return max_so_far; }
Now modify this to print the start and end indices.
- Anand Barnwal in India| Report Duplicate | Flag | PURGE
Adobe Developer Program Engineer Algorithm - 0of 0 votes
AnswersWhat is sister delegation and how is it implemented ?
- Anand Barnwal in India| Report Duplicate | Flag | PURGE
Adobe Intern C++ - 0of 0 votes
AnswersHow to design a LRU cache using heap(priority queue) ?
- Anand Barnwal in India| Report Duplicate | Flag | PURGE
Amazon Intern design - 2of 2 votes
AnswersAssume we have a very large file containing millions of lines of data. Only 2 lines are identical, rest are unique.
- Anand Barnwal in India
Each line is long enough that they may not fit in memory.
Design an efficient algorithm to determine identical lines?
And, then generalize it for 'n' identical lines.| Report Duplicate | Flag | PURGE
Microsoft Algorithm - 2of 4 votes
AnswersYou are standing before two doors.One door leads to the heaven and the other leads to Hell but you don't know what hides behind the doors. There are two gatekeepers. You know one of them always tells the truth and the other always lies, but you don't know who is the honest one and who is the liar.
- Anand Barnwal in India
You can only ask one question to one of them in order to find the way to heaven. What is the question?| Report Duplicate | Flag | PURGE
Intuit Intern Puzzle - 0of 0 votes
AnswerIs there any limit on the size of array (both static and dynamic) creation in C?
- Anand Barnwal in India| Report Duplicate | Flag | PURGE
Intern - 0of 0 votes
AnswersWrite a program that deletes every 5th byte from a file, but without using a temporary file or allocating a buffer in the memory. For adjusting the size of the file you may use the truncate function.
- Anand Barnwal in India| Report Duplicate | Flag | PURGE
Morgan Stanley Intern Algorithm
Use fseek to find the size of file and then read backwards from the end until n line breaks are read and then print the result.
Another solution can be like this:
Take a buffer for n lines and keep updating the buffer while reading from the files. So that at last the buffer contains the last n lines.
But it is given that the complete line may not fit in memory.
- Anand Barnwal June 08, 2015Pangrams are sentences constructed by using every letter of the alphabet at least once.
like: "The quick brown fox jumps over the little lazy dog"
If the range of number is not known then:
1 > Sort the array in non descending order
2 > Pick the first(lower index) and last(higher index) elements and add
3 > Now compare with '12' if less, then increment lower index and if greater, then decrement the higher index. Do it until lower index is less than higher index or pair
is found.
If the range of number is known:
1) Create and initialize a binary "Hash Map" M[] = {0, 0, …} of size equals to range
2) Do following for each element in array
(a) If M[x - Array[i]] is set(i.e. 1) then print the pair (A[i], x – A[i])
(b) Set M[A[i]]
Note:
If range of numbers include negative numbers then also it works. All we have to do for negative numbers is to make everything positive by adding the absolute value of smallest negative integer to all numbers.
Suppose the elements of array are : { -4, 1, 2, -8 } and x = -6
Then add '8' to each element of the array and '8+8' to x.
So, now your array becomes: {4, 9, 10, 0} and x becomes 10.
int main(int argc, char* argv[])
{
FILE *fp_read, *fp_write;
int counter = 1, i = 0;
char ch;
fp_read = fopen("input_file.txt", "r");
fp_write = fopen("input_file.txt", "r+");
if(!fp_read || !fp_write)
{
printf("File not present\n");
exit(1);
}
fseek(fp_read, 0, SEEK_END);
int size = ftell(fp_read);
printf("Size = %d\n", size);
fseek(fp_read, 0, SEEK_SET);
while(counter < size)
{
ch = fgetc(fp_read);
if(counter % 5 != 0)
{
fputc(ch, fp_write);
}
else
i++;
//printf("%c ", ch);
counter++;
}
fclose(fp_read);
fclose(fp_write);
printf("Trucate by %d bytes", i);
//Here truncate the file by "i" size
return 0;
}
RepAmber Van is the top rated company that offers friendly and professional removals services.Our featured services includes domestic moves ...
Padding is done to make data storage word aligned as accessing of word aligned data is fast.
- Anand Barnwal June 12, 2015