a question from Microsoft.

Implement BigInt class (with +,-,*,-,^)

answers link:

http://www.carljohansen.co.uk/bigint/

http://www.carljohansen.co.uk/bigint/BigInt.cs.txt

Implement BigInt class (with +,-,*,-,^)

answers link:

http://www.carljohansen.co.uk/bigint/

http://www.carljohansen.co.uk/bigint/BigInt.cs.txt

find the sum of contiguous subarray within a one-dimensional array of numbers which has the largest sum

answer :

http://geeksforgeeks.org/?p=576

answer :

http://geeksforgeeks.org/?p=576

How do you reverse the words in a string?

"My name is Yet Another Software Junk"

to

"Junk Software Another Yet is name My"

answer:

1. first reverse the string

"My name is Yet Another Software Junk" to

"knuJ erawtfoS rehtonA teY si eman yM"

2. reverse word by word now

"knuJ erawtfoS rehtonA teY si eman yM" to

"Junk Software Another Yet is name My"

You are given a circular single linked list of sufficiently many number of

nodes(say more than 1 crore). You need to delete a node say P and you are

given a pointer to P in the circular single list.

Suggest the most efficient methodology of deleting the node P from the

circular single linked list without rounding about the circular single

linked list.

Answer:

We have a list looking like: ... -> Node(i-1) -> Node(i) -> Node(i+1) -> ... and we need to delete Node(i).

- Copy data (not pointer, the data itself) from Node(i+1) to Node(i), the list will look like: ... -> Node(i-1) -> Node(i+1) -> Node(i+1) -> ...
- delete the second Node(i+1), it doesn't require pointer to the previous node.

answer in my mind:

1. travel the linked list for n times

(if you hit null in between, return null)

2. Then travel the linked list till end

(remember to increment the n-node pointer along with traversal)

1. travel the linked list for n times

(if you hit null in between, return null)

2. Then travel the linked list till end

(remember to increment the n-node pointer along with traversal)

Linked List B meet Linked List A at node J. find J

linked list A. heada->x->....->J->......->z->null

linked list B headb->y->....->J

linked list A. heada->x->....->J->......->z->null

linked list B headb->y->....->J

A sorted array . for eg: 2,3,6,8,11,23,56,89

It is right shifted unknown times eg: 23,56,89,2,3,6,8,11

now search an element in the array... say eg:56.

(no linear search allowed.)

answer in my mind:

1. first find the largest element by log(n)

2. now remove the first part or last part depends on search element.

3. now log(n) search for the item.

It is right shifted unknown times eg: 23,56,89,2,3,6,8,11

now search an element in the array... say eg:56.

(no linear search allowed.)

answer in my mind:

1. first find the largest element by log(n)

2. now remove the first part or last part depends on search element.

3. now log(n) search for the item.

a c-program to find the endians of a processor?

answer:

unsigned int i = 0xabcdefgh;

unsigned char *pc = (unsigned char *) &i;

if (*pc == 0xgh) {

/* little endian */

} else {

/* big endian */

}

answer:

unsigned int i = 0xabcdefgh;

unsigned char *pc = (unsigned char *) &i;

if (*pc == 0xgh) {

/* little endian */

} else {

/* big endian */

}

Here is a C puzzle I(PCE) got from Bestin:

You have a magical program `a.c'. When you type `cc a.c', your compiler appears to hang (ie, you don't get back the prompt). Now,during this time, you will be able to type any program `b.c' in the standard input and type Ctrl-D. Once you do this, you get back the prompt. Now, you type `a.out' and magic, what you get will be the output of program `b.c'! Question is, what is this program `a.c'?

Not a puzzle exactly.

Q. Are you familiar with curly bracket matching in vi editor?

(FYI: you may use % to find matching curly brackets)

implement this feature in 'your own' editor.

[you may even give a single-WORD-answer :-]

To simplify the question...

imagine a text with curly brackets like the following

"{{}{{}{}}{}}"

Input/output:

2nd curly matches with 3rd

1st curly with last one

4th with 9th

Now start writing the program.

Q. Are you familiar with curly bracket matching in vi editor?

(FYI: you may use % to find matching curly brackets)

implement this feature in 'your own' editor.

[you may even give a single-WORD-answer :-]

To simplify the question...

imagine a text with curly brackets like the following

"{{}{{}{}}{}}"

Input/output:

2nd curly matches with 3rd

1st curly with last one

4th with 9th

Now start writing the program.

July 2005 August 2005 October 2005 December 2005 March 2006 June 2006 July 2006 December 2006 February 2007 June 2007 March 2010 May 2010

Subscribe to Posts [Atom]