[algogeeks] Find Max Sum Value Pairs

2011-09-01 Thread Navneet Gupta
Given two sorted positive integer arrays A(n) and B(n), we define a set S = {(a,b) | a in A and b in B}. Obviously there are n2 elements in S. The value of such a pair is defined as Val(a,b) = a + b. Now we want to get the n pairs from S with largest values. need an O(n) algorithm. -- Regards,

[algogeeks] Find the element in Array

2011-08-31 Thread Navneet Gupta
You are given an array. One integer is in the array twice and others are unique. Find that no. O(n) Solution -- Regards, Navneet -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com.

[algogeeks] Re: String Problem

2011-08-31 Thread Navneet Gupta
The important thing to notice here is that relative order of characters is important and hence you should not look for just count char based approaches. On Wed, Aug 31, 2011 at 11:20 AM, Navneet Gupta navneetn...@gmail.com wrote: Given two strings S1 and S2, Find whether another string S3 can

[algogeeks] Sort problem

2011-08-30 Thread Navneet Gupta
Given an array of size n wherein elements keep on increasing monotically upto a certain location after which they keep on decreasing monotically, then again keep on increasing, then decreasing again and so on. Sort the array in place (ie. using only O(1) extra memory) -- Regards, Navneet --

[algogeeks] Any PHP experts out there?

2011-08-29 Thread Navneet Gupta
Any suggestions/references for same? have done web programming in past, but not so much creating websites with dynamic content/database integration etc. Also, i plan to start with WAMP model as i use Windows as my primary dev platform. -- Regards, Navneet -- You received this message because

[algogeeks] Zig Zag tree traversal

2011-08-28 Thread Navneet Gupta
Print tree in zig zag manner 1 / \ 23 / \ / \ 4 56 7 O/P: 1 3 2 4 5 6 7 -- Regards, Navneet -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

[algogeeks] Print tree like a tree

2011-08-28 Thread Navneet Gupta
Hope the question is clear. Basically you need to print a given tree such that spaces will depict the left/right relation at every level. output should be something like a b c d e f g Levels are separated by new lines. Notice that space

[algogeeks] Playdom Interview ques

2011-08-26 Thread Navneet Gupta
Posting few questions which Playdom asked a friend of mine in telephonic interviews. He had to write code in all cases. 1. Print m*n matrix in spiral form. Modify to make it iterative. 2. Print level order traversal or tree along with level information. Tree need not be complete a 1 b c

[algogeeks] Re: Playdom Interview ques

2011-08-26 Thread Navneet Gupta
One thing i should mention in ques3, you have the parent pointer of node. (so left, right and parent pointers can be used) On Fri, Aug 26, 2011 at 3:22 PM, Navneet Gupta navneetn...@gmail.comwrote: Posting few questions which Playdom asked a friend of mine in telephonic interviews. He had

[algogeeks] Given a number, return the least prime greater than number

2011-08-25 Thread Navneet Gupta
Needless to say. looking for an efficient solution rather than trying successive numbers from given number for primality. Any method? A general purpose use of above is to calculate N for hash functions. (index = key%N where N is prime). -- Regards, Navneet -- You received this message because

[algogeeks] Question from Google interview

2011-08-18 Thread Navneet Gupta
Given a string containing multiple words such that spaces between words is missing. Also, you have a dictionary containing valid words. Ex. Thatwouldbefantastic Output a string with proper spaces inserted. Output - That would be fantastic The case of words like bandwidth present can be

[algogeeks] HASHTABLE - what's the big deal?

2011-08-17 Thread Navneet Gupta
Hello, Many a times, i have noticed on blogs/sites that people emphasize a lot on the importance of hash tables for interviews. Though i do not disagree with their importance, i would really like to understand what kind of questions can be solved best only by hash tables and are also dear to

[algogeeks] Komli Media

2011-08-16 Thread Navneet Gupta
Any feedback on Komli Media? How's their compensation like for college freshers? Any interview questions you would like to share? -- Regards, Navneet -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

[algogeeks] Any links/resources on Recurrence Relations?

2011-08-15 Thread Navneet Gupta
Looking for a brief reference to solving recurrence relations. (Methods to deduce functions from recurrence relations) -- Regards, Navneet -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

[algogeeks] Re: Design a concurrent hash table

2011-08-15 Thread Navneet Gupta
Any takers? On Thu, Aug 11, 2011 at 3:45 PM, Navneet Gupta navneetn...@gmail.comwrote: Q. Design a concurrent hash table with as much as concurrency as possible. System has multiple readers and writers. System will crash if a reader or writer is reading or writing from a location which

[algogeeks] Design a concurrent hash table

2011-08-11 Thread Navneet Gupta
Q. Design a concurrent hash table with as much as concurrency as possible. System has multiple readers and writers. System will crash if a reader or writer is reading or writing from a location which is being updated by some writer. We need to prevent crash. It is pretty much an open-ended

[algogeeks] Graph Based Problems

2011-07-26 Thread Navneet Gupta
Hello folks, I have seen some of the best possible string/array/tree based problems being discussed on this thread but somehow i feel this group has been little partial towards Graph problems. Though, in most cases, interviewers don't ask Graph algorithms, but we, as algo lovers, should give due

[algogeeks] Book Reco for Computer Networks

2011-07-19 Thread Navneet Gupta
Looking for a book which explains networks like Bruce Eckel explains OOP :) . Enough said -- Regards, Navneet -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe

[algogeeks] Add Two Numbers stored in Linked Lists

2011-07-18 Thread Navneet Gupta
Write a recursive routine to add two numbers stored in Linked List in O(n) time and return result in List 3 Lists are not to be reversed. Example: List 1 : 1 2 3 4 5 (Num1 - 12345) List 2 : 6 7 8 (Num2 - 678) List 3 (output) - 1 3 0 2 3 (12345 + 678) -- Regards, Navneet -- You

[algogeeks] Reverse a List with Recursion

2011-07-17 Thread Navneet Gupta
Hi, I was trying to accomplish this task with the following call , header = ReverseList(header) I don't want to pass tail pointer or anything and just want that i get a reversed list with new header properly assigned after this call. I am getting issues in corner conditions like returning the

[algogeeks] Test Mail - Plz ignore

2011-07-14 Thread Navneet Gupta
Sending a test mail after re-joining the group. Please ignore. -- Regards, Navneet -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] Max Arithmetic Subsequence

2011-07-14 Thread Navneet Gupta
It worked fine on sorted input. On Wed, Jul 13, 2011 at 5:46 AM, Navneet Gupta navneetn...@gmail.com wrote: OOPS..Bad miss :( On Tue, Jul 12, 2011 at 11:53 PM, sunny agrawal sunny816.i...@gmail.com wrote: Algorithm in the paper says works only on sorted arrays it is mentioned

[algogeeks] Image based Problem (Google)

2011-07-12 Thread Navneet Gupta
Given 1000 million x 1000 million image, What information of this image to be stored such that you can find the locations when the given image has modi cations -- Regards, Navneet -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to

Re: [algogeeks] Reversing the order of words in String

2011-07-12 Thread Navneet Gupta
@Saurabh, just to let you know, compiler actually does that. Without traversing the array (read specifying the array size), you are able to free up all the memory being consumed by simply writing delete []a. On Tue, Jul 12, 2011 at 10:13 PM, saurabh singh saurab...@gmail.com wrote: and how

Re: [algogeeks] Reversing the order of words in String

2011-07-12 Thread Navneet Gupta
:54 PM, saurabh singh saurab...@gmail.com wrote: can strlen do the same job? I doubt...? On Tue, Jul 12, 2011 at 10:51 PM, Navneet Gupta navneetn...@gmail.com wrote: @Saurabh, just to let you know, compiler actually does that. Without traversing the array (read specifying the array size

[algogeeks] Max Arithmetic Subsequence

2011-07-12 Thread Navneet Gupta
I wrote the code as someone gave the reference of the paper where algo to get max arithmetic subsequence was given. For an input of {2,9,4,1,6,7,8,3,10}, i am getting an output of 3, while it should be 5 for {2,4,6,8,10} Below is the implementation, can someone help me understand where am i

Re: [algogeeks] GOOGLE Q1

2011-07-10 Thread Navneet Gupta
Try this 1. Find the min and max in O(n) time. 2. For A.P. = mix to max/N , we find max possible subsequence. For example 1,2,3,0,4,7,19,6,8,10,24.(could be more but trying to show the approach) We see min = 1 and max = 8 hence we need to try for diff = 1 to 8/size(arr) In this case, we

Re: [algogeeks] GOOGLE Q1

2011-07-10 Thread Navneet Gupta
Sorry typo below On Sun, Jul 10, 2011 at 12:49 PM, Navneet Gupta navneetn...@gmail.comwrote: Try this 1. Find the min and max in O(n) time. 2. For A.P. = mix to max/N , we find max possible subsequence. For example 1,2,3,0,4,7,19,6,8,10,24.(could be more but trying to show

Re: [algogeeks] Reversing the order of words in String

2011-07-07 Thread Navneet Gupta
(pause); } On Thu, Jul 7, 2011 at 9:10 AM, Navneet Gupta navneetn...@gmail.com wrote: @Piyush, could you elaborate your approach with Linked List? From what i am getting, even with Linked List, you would need two traversals at least. On Thu, Jul 7, 2011 at 2:07 AM, Piyush Sinha ecstasy.piy

Re: [algogeeks] Amazon

2011-07-07 Thread Navneet Gupta
Can we do this? Start with a node, take an edge say between x1 and x2 of length k1. Take another node x3 and check distance between x1 and x3 (k13) and x2 and x3 (k23) Depending on whether k13 or k23 is bigger, the node x3 between x1 and x2 or away from x1 and after x2. Proceeding in this way

Re: [algogeeks] Reversing the order of words in String

2011-07-07 Thread Navneet Gupta
sys print .join((sys.argv[1].split())[::-1]) On Thu, Jul 7, 2011 at 3:12 PM, Navneet Gupta navneetn...@gmail.com wrote: @Vishal, can you see if your program works well for more than single space between words? Not sure how split functions helps. BTW, Perl also is very strong language

Re: [algogeeks] Reversing the order of words in String

2011-07-07 Thread Navneet Gupta
, Jul 7, 2011 at 3:36 PM, Navneet Gupta navneetn...@gmail.com wrote: @Vishal, Don't confuse printing in reverse with actually modifying the actual string to reverse word order in it :) On Thu, Jul 7, 2011 at 3:34 PM, Vishal Thanki vishaltha...@gmail.com wrote: @Navneet, it works with multiple

Re: [algogeeks] Reversing the order of words in String

2011-07-07 Thread Navneet Gupta
Okay, I think NO EXTRA SPACE is what i should have mentioned clearly. Anyways dude, i appreciate the point of simplicity which you are trying to show. On Thu, Jul 7, 2011 at 3:45 PM, Navneet Gupta navneetn...@gmail.com wrote: I meant, having the result in same string which was used as param

[algogeeks] Usage of static extern

2011-07-07 Thread Navneet Gupta
Hello, Can someone explain me why does linker perform the resolution when function is being defined in unmanaged code and is being used in managed code with signatures like public static extern Foo() . As i understand, the function should be a static one in unmanaged code and hence static

Re: [algogeeks] Explanation

2011-07-07 Thread Navneet Gupta
@Vishal, still the array str1 is also 10 bytes only, I know that memcpy overwrites the null character but not sure then what is the correct approach if i still want to use memcpy. Thoughts? On Fri, Jul 8, 2011 at 10:51 AM, Vishal Thanki vishaltha...@gmail.comwrote: you are overwriting

Re: [algogeeks] MS Question

2011-07-06 Thread Navneet Gupta
See diff documentation. It's an application of Longest Common Subsequence problem. http://en.wikipedia.org/wiki/Diff On Wed, Jul 6, 2011 at 11:12 AM, priyanshu priyanshuro...@gmail.com wrote: What is the most efficient way to compare two text documents?? Also we need to find the percentage by

Re: [algogeeks] solve this

2011-07-06 Thread Navneet Gupta
93747. Just defined the variables as x^2, x, y, x+1, 14-y and solved it with information in 5th statement. On Wed, Jul 6, 2011 at 5:28 PM, rupali chauhan chauhanrupal...@gmail.com wrote: Solve Dis! A Boy Forgot His Pin-Code Which Was Of 5 Digits, But Luckily He Remembered Some Hints How To 2

Re: [algogeeks]

2011-07-06 Thread Navneet Gupta
The basic reason is graduation. Since C++ is object oriented and designers wanted to provide more safety in case of dynamic memory allocations, they defined new and delete operators to handle allocation and deallocation. If you see malloc, if does only one function - allocate the memory, with

[algogeeks] Reversing the order of words in String

2011-07-06 Thread Navneet Gupta
I think somebody on this thread has asked this question but i am not able to find that. Question was if a string is like my name is ram, then output should be ram is name my. Wrote the code for same, so sharing. #includeiostream #includestring using namespace std; void SwapStringChars(string

Re: [algogeeks] Reversing the order of words in String

2011-07-06 Thread Navneet Gupta
tushicom...@gmail.com wrote: good job but how can this be done in one traversal as asked on the Adobe Interview Questions thread. On Wed, Jul 6, 2011 at 9:49 PM, Navneet Gupta navneetn...@gmail.com wrote: I think somebody on this thread has asked this question but i am not able to find

Re: [algogeeks] puzzle

2011-07-06 Thread Navneet Gupta
Just to let you guys know it's a good legitimate problem with no trick answer. People who don't know the solution should try. On Wed, Jul 6, 2011 at 10:44 PM, Tushar Bindal tushicom...@gmail.com wrote: Eggs can never break the building. So dropping the eggs won't break the building - whether

Re: [algogeeks] Reversing the order of words in String

2011-07-06 Thread Navneet Gupta
?? On 7/6/11, Tushar Bindal tushicom...@gmail.com wrote: I read that solution. But the same doubt as Navneet which I think you also raised i one of your posts on that thread On Wed, Jul 6, 2011 at 10:34 PM, Navneet Gupta navneetn...@gmail.comwrote: Saurabh, I understood your solution

Re: [algogeeks] Re: Some adobe interview questions.

2011-07-06 Thread Navneet Gupta
Anyone for Q10, i wonder if it can really be solved in O(n). Very obvious O(nlogn) is what I know On Thu, Jul 7, 2011 at 1:25 AM, KK kunalkapadi...@gmail.com wrote: for Q5 change the expr into postfix and then build expression tree... but is expression tree same as parse tree?? correct me if i

Re: [algogeeks] NVIDIA Q

2011-07-06 Thread Navneet Gupta
In this case, i think we will get sizeof(int) size of class because here the objects will automatically be referring to different memory location because of non-zero class size. Empty class looks like a special case where 'bonus' size is allocated. On Thu, Jul 7, 2011 at 11:04 AM, oppilas .

Re: [algogeeks] Re: Nagarro Question

2011-07-05 Thread Navneet Gupta
I solved it without any temp variables and the solution works like magic. Suppose the sequence is A1, A2, A3, A4, A5 B1, B2, B3, B4, B5 Now here N = 5. I had to perform 1+2+3+4 = N(N-1)/2 swaps to get the desired order. The scheme work like this. At step 1, perform only one Swap - A5, B1 Now

Re: [algogeeks] Unique substring

2011-07-05 Thread Navneet Gupta
I think you guys are on different page. There is a difference between substring and subsequence. http://en.wikipedia.org/wiki/Subsequence#Substring_vs._subsequence This question asks what is the longest SUBSTRING which is unique (there could also be none or multiple if lengths are equal)

[algogeeks] Flatten a BST to produce inorder traversal

2011-07-04 Thread Navneet Gupta
Tree has an extra pointer next apart from left and right. Objective is to set next pointer to point to node successor in the tree. Following the next pointer, we would be able to produce sorted list. Looking for both a recursive and non-recursive approach. --Navneet -- You received this

Re: [algogeeks] Flatten a BST to produce inorder traversal

2011-07-04 Thread Navneet Gupta
://en.wikipedia.org/wiki/Threaded_binary_tree On Mon, Jul 4, 2011 at 11:34 PM, Navneet Gupta navneetn...@gmail.comwrote: Tree has an extra pointer next apart from left and right. Objective is to set next pointer to point to node successor in the tree. Following the next pointer, we would be able

Re: [algogeeks] Re: array size problem

2011-07-03 Thread Navneet Gupta
If you can, refer to Constants chapter in Bruce Eckel. He he smartly explained how const are different for C C++. The e-book is free to download from net. On Mon, Jul 4, 2011 at 2:50 AM, Gene gene.ress...@gmail.com wrote: Why do bicycles have 2 wheels and tricycles 3?  The designers made them

Re: [algogeeks] Delete a node in a BST!!

2011-07-03 Thread Navneet Gupta
It is a simple algorithm 1) If node has no child, simply delete 2) If node has one child, replace node's data with child's data and make the subtree child of node, delete child. 3) if node has two child, find the node with min key in right subtree (or max in left subtree), call it x, replace

Re: [algogeeks] find output

2011-07-03 Thread Navneet Gupta
I think one rule of thumb for reading pre and post increment operators is 1) For Pre - Increment the value and use it (++x) 2) For Post - Use the value and increment it (x++) Similar is for pre and post decrement. I am not very good at commenting the generality of above but in simple usages

Re: [algogeeks] Re: Sum to K problem

2011-07-02 Thread Navneet Gupta
:53 PM, Navneet Gupta navneetn...@gmail.comwrote: Ideally, yes it can. Though i would be happy even if someone gives a good answer for non-negative values. On Mon, Jun 20, 2011 at 6:28 PM, Akshata Sharma akshatasharm...@gmail.com wrote: @Navneet: does the set contains negative

Re: [algogeeks] Dynamic Programming problem

2011-07-02 Thread Navneet Gupta
This is a recently discussed problem in this group. Refer to subset sum problem. http://en.wikipedia.org/wiki/Subset_sum_problem On Sun, Jul 3, 2011 at 6:34 AM, Edmon ebeg...@gmail.com wrote: I need a help with this dynamic programming problem please. It is from the entrance exam practice

Re: [algogeeks] Re: GOOGLE QUESTION

2011-06-30 Thread Navneet Gupta
I wonder why people have discarded the idea of Hash map here. Searching is obviously the most important task here and if we are to assume that names can be uniformly hashed over a table of 1000 rows with each row containing 1000 names each. Further optimization can be achieved by having names

Re: [algogeeks] Binary Tree

2011-06-28 Thread Navneet Gupta
Sunny, the solution is great. Could you give me some ideas around how do you approach such problems in recursive manner? Recursion is never easy for me to understand as it is difficult to visualize. On Tue, Jun 21, 2011 at 11:52 PM, sunny agrawal sunny816.i...@gmail.com wrote: see this

[algogeeks] Algorithms

2011-06-28 Thread Navneet Gupta
http://en.wikipedia.org/wiki/List_of_algorithms How many do you know? :) --Navneet -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to

Re: [algogeeks] OS

2011-06-27 Thread Navneet Gupta
One such resource http://placementsindia.blogspot.com/search/label/Operating%20Systems On Mon, Jun 27, 2011 at 2:01 PM, Nishant Mittal mittal.nishan...@gmail.com wrote: plz recommend me some good sites for OS interview questions... Thanx in advance -- You received this message because

RE: [algogeeks] string matching

2011-06-23 Thread Navneet Gupta
String matching can be performed in linear time with KMP algorithm. could you say what more optimization you are looking for here? Sent from my Windows Phone -- From: prateek gupta Sent: 23/06/2011 11:17 To: algogeeks@googlegroups.com Subject: [algogeeks] string

RE: [algogeeks] Re: If any one have algorithms for interviews by adnan aziz ebook... Please mail ...

2011-06-23 Thread Navneet Gupta
Even I am getting permission error in accessing the google doc Sent from my Windows Phone From: pullasunil Sent: 23/06/2011 12:14 To: Algorithm Geeks Subject: [algogeeks] Re: If any one have algorithms for interviews by adnan aziz ebook... Please mail ... Can you mail me the book for Algorithms

Re: [algogeeks] Re: sort the array

2011-06-22 Thread Navneet Gupta
Let the array elements be 2,3,5,10 1,4,8,12. Have two index variables m and n. Intially m will point to 2 and n to 1. 1. Compare the elements in m and n. 2. If elem[m] elem[n] swap, increment n 3. else increment m and go to step 1. 4. end if m becomes the starting value of n or n reaches end

Re: [algogeeks] [Brain Teaser] Extraordinary Riddle 21 june

2011-06-21 Thread Navneet Gupta
Time-Date was 12:34 5/6/78 On Tue, Jun 21, 2011 at 1:31 PM, Lavesh Rawat lavesh.ra...@gmail.com wrote: Extraordinary Riddle  21 june Something Extraordinary happened on May 6th 1978 at 12:34am what was that? Update Your Answers at : Click Here Solution: Will be updated after 1 day --

Re: [algogeeks]

2011-06-21 Thread Navneet Gupta
One crude idea could be to generate permutations of all substrings of seq2 and then check if any of such permutations is a substring of seq1. Maintaining a count for chars in substring generated and updating it every time we get a higher value. ^thinking for better solution. On Tue, Jun 21, 2011

Re: [algogeeks] Amazon

2011-06-21 Thread Navneet Gupta
I think searching for palindromes with same starting and ending characters and required lengths to construct the rectangle is one tricky way i can think of. For generic solution, a good data structure i can think of is a table of trees. We need to find the shortest and longest word and then

[algogeeks] Sum to K problem

2011-06-20 Thread Navneet Gupta
Given a set of integers , find a set of numbers such that they sum to a given number k . Notice the set of numbers can have 2 or more than 2 numbers. --Navneet -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email

Re: [algogeeks] Sum to K problem

2011-06-20 Thread Navneet Gupta
20, 2011 at 12:09 PM, oppilas . jatka.oppimi...@gmail.comwrote: I think its a NP problem. The solution complexity can go up O(2^N) in worst case. On Mon, Jun 20, 2011 at 11:55 AM, Navneet Gupta navneetn...@gmail.comwrote: Given a set of integers , find a set of numbers such that they sum

[algogeeks] Coin Chain Reaction

2011-06-20 Thread Navneet Gupta
We have an unlimited number of dice at our disposal. Let's roll the die. If the outcome is 1, 2, or 3, we stop; otherwise, if it is 4, 5, or 6, a corresponding number of dice are rolled. For example, if the first roll gives 5, then we roll 5 dice, and so on. This procedure continues for every

Re: [algogeeks] Sum to K problem

2011-06-20 Thread Navneet Gupta
binary search in rest of the array : order nlogn hence u get two elements which sum up to K in order nlogn On Mon, Jun 20, 2011 at 12:14 PM, Navneet Gupta navneetn...@gmail.com wrote: Right, in the worst case, complexity with be O(2^N). So what are the possible optimizations here? Would

RE: [algogeeks] Coin Chain Reaction

2011-06-20 Thread Navneet Gupta
Can you discuss how did you arrive at this value? Sent from my Windows Phone -- From: sunny agrawal Sent: 20/06/2011 22:53 To: algogeeks@googlegroups.com Subject: Re: [algogeeks] Coin Chain Reaction and Expected value should be 2.5^(N-1)*(7/2) -- Sunny Aggrawal

[algogeeks] Minimum draws for correct labels

2011-06-20 Thread Navneet Gupta
IMAGINE THAT YOU have three boxes, one containing two black marbles, one containing two white marbles, and the third, one black marble and one white marble. The boxes were labeled for their contents-BB, WW and BW-but someone has switched the labels so that every box is now incorrectly labeled. You

Re: [algogeeks] Minimum draws for correct labels

2011-06-20 Thread Navneet Gupta
does not contain while, it can either have BB or BW ball. But it must have BB ball inside it otherwise, we will end up getting BB in correct labeled BB box. On Tue, Jun 21, 2011 at 12:11 AM, Radhika Renganathan radi.coo...@gmail.com wrote: one drawing ?! On 6/21/11, Navneet Gupta

Re: [algogeeks] Re: Finding the min gap in 3 arrays

2011-06-18 Thread Navneet Gupta
I have come up with this approach. Take first two arrays and compute the min absolute difference between two elements. Then with this mingap2 between A1 and A2, add each element and check what is the least value possible. Below is the code. Think it should work. I have not considered negative

Re: [algogeeks] Re: find output.

2011-06-16 Thread Navneet Gupta
@Sunny, it is good that you follow Bruce Eckel, but copy pasting the exact thing? :) On Thu, Jun 16, 2011 at 7:34 PM, keyan karthi keyankarthi1...@gmail.comwrote: hi friends is a string literal.. ie the string hi friends is stored somewhere and a pointer to its base address is returned to

Re: [algogeeks] Re: find output.

2011-06-16 Thread Navneet Gupta
at 8:06 PM, Navneet Gupta navneetn...@gmail.comwrote: @Sunny, it is good that you follow Bruce Eckel, but copy pasting the exact thing? :) On Thu, Jun 16, 2011 at 7:34 PM, keyan karthi keyankarthi1...@gmail.comwrote: hi friends is a string literal.. ie the string hi friends is stored

Re: [algogeeks] a doubt..

2011-06-14 Thread Navneet Gupta
, snehi jain snehijai...@gmail.com wrote: wont recursion will also be resource (time) intensive because of the multiple function call which is not observed in iterative procedures. On Tue, Jun 14, 2011 at 7:30 AM, Navneet Gupta navneetn...@gmail.comwrote: Recursion is the best way to write compact

Re: [algogeeks] Find shortest substring that is only occurring once. in Given String

2011-06-14 Thread Navneet Gupta
This looks like a good problem. Could you confirm if string contains only two characters as you mentioned in both examples or it is a general string with any characters. On Tue, Jun 14, 2011 at 6:33 PM, bittu shashank7andr...@gmail.com wrote: I found one interesting question Given a string s

Re: [algogeeks] Interview Question: Puzzle: Probability

2011-06-14 Thread Navneet Gupta
Put one red ball in one jar and rest 99 balls in other jar. Probability in that case is 1/2*1 + 1/2*49//99 On Tue, Jun 14, 2011 at 7:45 PM, Vishal Jain jainv...@gmail.com wrote: Folks, This question was asked during a screening process of a product based company. Please answer.

Re: [algogeeks] a doubt..

2011-06-13 Thread Navneet Gupta
Recursion is the best way to write compact programs for what might seem as tedious tasks to do. Dynamic Programming is an alternate to recursion when problems possess characteristics like suboptimal substructures and overlapping subproblems. Dynamic Programming is a iterative way of doing tasks

[algogeeks] Intuitive Understanding of XOR Operation

2011-06-13 Thread Navneet Gupta
Hello, I would really appreciate if someone can help me get an intuitive understanding of XOR over a range of numbers. I have seen it's usage is a couple of problems where duplicates are involved and though ultimately i can see how it is solving the problem, i still feel like checking the

[algogeeks] Print 1 to n without loops

2011-06-10 Thread Navneet Gupta
Take n from user and print 1 to n. No loops like for/while/do-while are allowed to use. --Navneet -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group,

Re: [algogeeks] Print 1 to n without loops

2011-06-10 Thread Navneet Gupta
No. On Fri, Jun 10, 2011 at 9:26 PM, nagajyothi gunti nagajyothi.gu...@gmail.com wrote: Can goto statement be used? On Fri, Jun 10, 2011 at 11:42 AM, Navneet Gupta navneetn...@gmail.comwrote: Take n from user and print 1 to n. No loops like for/while/do-while are allowed to use

Re: [algogeeks] Print 1 to n without loops

2011-06-10 Thread Navneet Gupta
Using recursion would be like using loops only. Also i believe the recursion used would be tail recursion and one can change tail recursion to loop based non recursive method. Okay, giving all a hint. Think classes and objects. On Fri, Jun 10, 2011 at 9:26 PM, Navneet Gupta navneetn

Re: [algogeeks] Print 1 to n without loops

2011-06-10 Thread Navneet Gupta
]; } this will print from 1 to 5 am i right? On Fri, Jun 10, 2011 at 9:30 PM, Navneet Gupta navneetn...@gmail.comwrote: Using recursion would be like using loops only. Also i believe the recursion used would be tail recursion and one can change tail recursion to loop based non recursive method

Re: [algogeeks] Re: please help me

2011-06-09 Thread Navneet Gupta
Try placementsindia.blogspot.com , it has a good collection of problems specific to placements. On Thu, Jun 9, 2011 at 12:23 PM, coder dumca coder.du...@gmail.com wrote: I need some more books specialy on algo ds and puzzles On Wed, Jun 8, 2011 at 4:07 AM, coder dumca coder.du...@gmail.com

Re: [algogeeks] need help in Desktop applications

2011-06-09 Thread Navneet Gupta
I would recommend you to read complete Java Reference book by Herbert Schildt, it will take you nicely through the basics of creating window based applications. First read the chapters on Applets and AWT and then you should be able to easily and naturally graduate to using Swing. On Thu, Jun 9,

Re: [algogeeks] need help in Desktop applications

2011-06-09 Thread Navneet Gupta
of Applets and AWT and have started getting acquainted to Swing but the problem lies where to start from. Its like I want a small example or few starting steps. Complete Reference is the book that i refer. On Thu, Jun 9, 2011 at 1:48 PM, Navneet Gupta navneetn...@gmail.com wrote: I would recommend

Re: [algogeeks] Regular Expressions Implementation

2011-06-09 Thread Navneet Gupta
So i assume your ask is given a string, check if it can be formed with the regular expression you have. Is that correct? The above can be implemented easily with stacks. Ex - Reg Expression - a*bc* And String - aabccc Put all instances of char that are consecutive on the stack and then pop the

Re: [algogeeks] MS Interview

2011-06-09 Thread Navneet Gupta
The answer to second question is simple. XORing all the elements should do it for you. On Thu, Jun 9, 2011 at 3:15 PM, Dumanshu duman...@gmail.com wrote: Q1. I  have a file in which there are supposed to be 4 billion numbers, starting from 1 to 4,000,000,000 but unfortunately one number is

Re: [algogeeks] Finding total number of inversions in an array in O(nlogn) complexity .

2011-06-09 Thread Navneet Gupta
Insertion sort also would do. On Thu, Jun 9, 2011 at 4:22 PM, D.N.Vishwakarma@IITR deok...@gmail.com wrote: thanx for suggestion On Thu, Jun 9, 2011 at 4:08 PM, sunny agrawal sunny816.i...@gmail.com wrote: Discussed many times, 1) add some lines to merge sort 2) use Binary indexed tree

RE: [algogeeks] Finding total number of inversions in an array in O(nlogn) complexity .

2011-06-09 Thread Navneet Gupta
in an array in O(nlogn) complexity . how insertion sort will do in O(nlogn)? On Thu, Jun 9, 2011 at 4:27 PM, Navneet Gupta navneetn...@gmail.com wrote: Insertion sort also would do. On Thu, Jun 9, 2011 at 4:22 PM, D.N.Vishwakarma@IITR deok...@gmail.com wrote: thanx for suggestion On Thu, Jun 9

[algogeeks] Sudoku

2011-06-07 Thread Navneet Gupta
What could be a good strategy to check if the given Sudoku puzzle is indeed solvable? Can you think of anything other than actually trying to solve it and later finding it is not solvable. Even good ideas for optimizations are welcome. --Navneet -- You received this message because you are

[algogeeks] Re: Sudoku

2011-06-07 Thread Navneet Gupta
A little different but related problem is to determine whether a Sudoku puzzle is easy, medium or hard to solve. Here, solveability is guaranteed. On Tue, Jun 7, 2011 at 2:31 PM, Navneet Gupta navneetn...@gmail.com wrote: What could be a good strategy to check if the given Sudoku puzzle

Re: [algogeeks] challenging problem , looking for a quick and a best algorithm

2011-06-07 Thread Navneet Gupta
Well, one approach is have all possible sums stored for debits and credits and match the sums. Basically, you can create a multi-list type DS (if i remember the name correctly) and store the SUMS and with formative elements in linked lists being pointer by node containing sums SUM 1 - Header 1 -

Re: [algogeeks] Re: Read a data from given particular memory location in C++

2011-06-04 Thread Navneet Gupta
Can't think of any trivial/straight forward way of doing that other than dereferencing pointer. On Sat, Jun 4, 2011 at 3:34 PM, D.N.Vishwakarma@IITR deok...@gmail.com wrote: I'm saying that int *x=new int(3); is a statement . I want to find value at location allocated by new which is 3 in this