Varun
BAN USER- 1of 1 vote
AnswersU are given a set of strings, using the characters of the given string, the program needs to find the maximum length string that doesn't has any of the given string as its sub-string. In case, if we can have infinite long string satisfying the property, print -1.
- Varun in India
I solved this, but looking forward to some convincing algo.
eg 1:
11, 00
longest: 010101010101010101010101... (-1, as infinite long)
eg2
101, 111, 00, 110
longest:010(i think, maybe wrong)| Report Duplicate | Flag | PURGE
Tech Lead Algorithm - 0of 0 votes
AnswersGiven an array of n elements. The array can have duplicates.
- Varun in India
Now sort the array based on frequency of distinct number in array.
eg: a= [3,4,2,5,3,3,4,2,1,5}
output = {3, 4,2,5,1} coz, 3 occurs thrice, 4,2,5 occurs twice, so they are retained in order of there occurrence in original array, and at last 1, as it appears least number of time.| Report Duplicate | Flag | PURGE
Tribal Fusion Software Engineer / Developer Algorithm - 0of 0 votes
AnswerAsked few times over phone and in-person.
- Varun in India
Asking to get my facts correct and consolidate the info for me and for everyone here.
How's synchornization differs in multi-core vs multiprocessor arch?
Little internals about them.
How the code design and implementation changes for these two arch?
pour in your suggestions and any nice read if u know any.| Report Duplicate | Flag | PURGE
Software Engineer / Developer Computer Architecture & Low Level - 0of 0 votes
Answersint a[10]; a[-1] = 20;
where is 20 stored?
- Varun in India
I said this won't compile in C under normal circumstances, he agreed, and then said let's assume C allows this, what happens?? I said maybe then previous local variable of the function will get overwritten with this value.?? Nay insights?| Report Duplicate | Flag | PURGE
Hewlett Packard C - 0of 0 votes
Answersdefine a struct imitate ip_header as it is in a packet.
- Varun in India
actually, he wanted to see how i handle things with aren't a byte long or odd number of bytes long, like flags, ihl, version and all.
what's the best struct to define a ip_header, and tcp header.| Report Duplicate | Flag | PURGE
Samsung Software Engineer / Developer C - 0of 0 votes
Answerswrite a program to convert char *mac_address to int array.
- Varun in India
eg mac_address ="ab:cd:ef:12:34:56" to
result= [ab, cd, ef, 12,34,56]
I was able to do it, but wasn't sure, how do we store hex values in int array. i mean a[0]=a, will essentially be a[0]=10, can we store hex directly in array, so that when we do memcmp or something, we can directly compare hex against hex?
Not sure if me making sense here, still let me know, if you have suggestions.| Report Duplicate | Flag | PURGE
Samsung Software Engineer / Developer C - 0of 0 votes
Answerscome up with a solution, where u r given a single pointer in a single link list and u shoudl be able to return (+/-)nth node from it.
My solution:list * returnN (list *node, int n) { if (n>0) { traverse and reverse list from node to nth node } else { traverse and negatereverse from node till nth node }
he asked for algo only, so this worked fine.
- Varun in India
eg list=1->2->3->4->5
returnN(1, 3)
output 4
list=1<-2<-3<-4->5
returnN(4, -2)
output 2
list: 1<-2->3->4->5
Any other suggestions??| Report Duplicate | Flag | PURGE
IBM Software Engineer / Developer Algorithm - 0of 0 votes
Answers2. write sizeof operator.
I gave the code as#define sizeof(data) {data *p=0; size = abs((p+1) - (p))
He was fine with this.
- Varun in India
But then how would we extend this to find sizeof of variables???
PS: sizeof in C that we use works well for both datastruct and variable.| Report Duplicate | Flag | PURGE
Samsung Software Engineer / Developer C - 0of 0 votes
Answerswhat is the return value of the function that returns int, but isn't returning anything explicitly.
for instance output ofint fun() { printf("\ncrap"); } void main() { printf("\n return value of fun %d", fun()); }
i said, should be exit status of 0(success) or value in EPI register, but looks like i wasn't corret. He said, this has something to do with stack unwinding??
- Varun in India
Any insights?| Report Duplicate | Flag | PURGE
Samsung Software Engineer / Developer C - 0of 0 votes
AnswersAssume you have a file with 5Mb size.
- Varun in India
Each line in file has a interger. (and only one integer per line).
Now, your system can process only 1Mb data at a time in memory, that is you cannot access more than 1Mb of data at a time.
Write a program that sort the file under this circumstances.
Answer I gave:
This problem is basically, you have array of 100 number, and at time you can access only 10 of them. Then sort the array.
He was happy to see this analogy, and then my algo.
Divide the array into 10 segments of each, and sort each one of them individually.
Now, take the first element of each sort subarray and find the min.
Put this min into differnt array of the size 100 at its starting location.
Repeat this process, for the next element from the subarray which had the smallest element as identified earlier.
He seemed to be ok with this.
Any other approach?| Report Duplicate | Flag | PURGE
NetApp Software Engineer / Developer Algorithm - 0of 0 votes
Answersmain() { char *c; printf("\n%d", *c); printf("\n%d", c); printf("\n%d", &c); }
output of above program.
- Varun in India
*c some junk value, c some memory address, &c address where the pointer is stored.
Q. if we re-run the program, then what's the output.
A. all output may change.
He stressed that &c won't change, everything else might..but &c will remain same.??
I just tried on my unix box, and saw it to change?| Report Duplicate | Flag | PURGE
NetApp Software Engineer / Developer - 0of 0 votes
AnswersThis is incremental.
Q1. Write the the algo for linked list traversal.
Q2. Now, modify this to give the index of a element "x" in list (index== its location in list, rather number of comparison needed to finally get to X, else 0)
Q3. modify and give the prototype of function will work generally (that means a function prototype which takes any data strcutre(list, q, tree, heap), X, and return the count)
Q4. Now declare the function defined above.
Answers I gave:
1.bool traverse ( list * head) { while (head) {head=head->next;} return TRUE; }
2. bool findx (list *head, void *x, int num_bytes)
- Varun in India
{
bool ret = FALSE;
while (head) {
if (memcmp(head->data, x, num_bytes)){ ret=TRUE; return ret;}
else ret;
}
3. int findX(void *head, int (*traverse(void *node, void *x))
where *traverse is a function pointer that can be changed depending upon data structure for which we need to find the index of X.| Report Duplicate | Flag | PURGE
NetApp Software Engineer / Developer Algorithm
Random numbers are simply numbers which doesn't obey any reason.
Its basically like, at an instant a number comes to your mind for no reason.
Pseudo random numbers, are numbers generated using algorithm with high degree of randomness. Since machine can't simply come up with any number, the cases where we need random numbers for computers, we use random number generator algorithms, and the number they generate are called pseudo random number.
hope this helps
@Lakshmi, Agreed with your comment to "hprem991".
Back to our discussion, surely malloc and free are C libraries, but these don't do actual mem allocation/de-allocation rite? At the end, malloc/new or whatever, will end up using a system call lie brk, sbrk etc to get memory, and therefore its the kernel who will have access to metadata associated with each block allocated, and thereby meaning free maybe able to get hold of metadata, and free up things.
yes lakshmi, your opinion about CRT is correct, but I am still not convinced if this will lead to mem leak.
What I thought and answered was, it depends. Either free will free the complete memory of 10 bytes or will return failure, but it won't free the 9 bytes.
I was of the opinion, given a pointer, free using a system call will be able to figure out the metadata associated with the mem block, and should be able to free up the block..looks like i was wrong?
yes, u r correct. It compiles, and I fortunately was able to revert my answer during the interview to say yes, it will compile :P but wasn't sure.
But, Its not overwriting the previous argument..for instance
char a, b[10];
then b[-1] shouldn't overwrite a for a function stack??
Hey Laxmi,
thnx for pointing it out.
But, are u sure, do we have a space for return value on the stack for a function??
If I am correct, we don't have return value stored on stack, rather the value of EIP register is considered as return value for the function.
I might be wrong, but I am not convinced with your opinion.
I tried it just on my unix, and saw the value continues to be same for all instances of the program??
Also, gdb never showed any place where the return value is stored.
ideally no! if u mean ur RAM is infinite.
- Varun January 02, 2013but practically, in this scenario too we might want paging as it reduces the address space makes things portable etc.