[algogeeks] Re: interview questoin

2011-07-31 Thread Amit Jaspal
This is discussed before I think. It will be in O(n). On Jul 31, 1:15 pm, siva viknesh wrote: > using map ?? key - string , value - count..print d string whose count > is 1.. > > On Jul 19, 8:49 pm, "pacific :-)" wrote: > > > > > > > > > sorry. > > > On Tue, Jul 19, 2011 at 9:07 PM, Shubham Mahe

Re: [algogeeks] Re: Binary Tree Problem

2011-06-05 Thread Amit Jaspal
://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > *Piyush Sinha* > *IIIT, Allahabad* > *+91-8792136657* > *+91-7483122727* > *https://www.facebook.com/profile.php?id=10655377926 * > > -- > You received this message because you are subscribe

Re: [algogeeks] A Graph Problem

2011-06-05 Thread Amit Jaspal
.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- Amit Jaspal. Men do less than they ought, unless they do all they can -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To po

Re: [algogeeks] Array problem

2011-05-20 Thread Amit Jaspal
s 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 > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this grou

Re: [algogeeks] GOOGLE Q

2011-05-20 Thread Amit Jaspal
s" group. >> To post to this group, send email to algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >>

Re: [algogeeks] A SIMPLE C++ PROGRAM.

2011-05-01 Thread Amit Jaspal
; -- >> 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 >> algogeeks+unsubscr...@googlegr

Re: [algogeeks] Re: difference x

2010-12-23 Thread Amit Jaspal
scribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- Amit Jaspal Btech IT IIIT- Allahabad -- You received this message because you are subscribed to the Goo

Re: [algogeeks] Re: TopCoder Bad Neighbour

2010-12-22 Thread Amit Jaspal
. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- Amit Jaspal Btech IT IIIT- Allahabad -- You received this message because you are subs

Re: [algogeeks] 0's and 1's yet again!!!

2010-08-19 Thread Amit Jaspal
re subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com > . > For more options, visit this group at > htt

Re: [algogeeks] Longest SubSequence with Sum < K

2010-08-18 Thread Amit Jaspal
ecause you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com > . > For more options, visit this gro

Re: [algogeeks] Re: Data Structure for URL matching

2010-08-17 Thread Amit Jaspal
advantage of a ternary-search-tree? > > > On Aug 15, 8:31 pm, Amit Jaspal wrote: > > Seems a gud idea . > > I have read we can do better with Ternary Search Trees .Can anybody has > any > > idea about it? > > > > > > > > > > > &

Re: [algogeeks] Re: Data Structure for URL matching

2010-08-15 Thread Amit Jaspal
-- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com > . >

Re: [algogeeks] number of BST's

2010-07-29 Thread Amit Jaspal
-- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com &

Re: [algogeeks] Minimum Window String

2010-07-12 Thread Amit Jaspal
e can calculate the length of string S and T and > reverse the string whose length is smaller than the other. Then Take LCS of > it. To get the final answer. > > > > On Mon, Jul 12, 2010 at 7:05 AM, Amit Jaspal wrote: > >> @ above Consider S="anand" T={'d',&#

Re: [algogeeks] Minimum Window String

2010-07-12 Thread Amit Jaspal
r more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > With Regards > > Ankur Aggarwal > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" grou

Re: [algogeeks] Re: sort in O(n)

2010-07-12 Thread Amit Jaspal
"Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com . For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- Amit Jaspal Bte

Re: [algogeeks] Difference b/w two elements in a array

2010-07-11 Thread Amit Jaspal
st to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- Amit Jaspal Btech IT IIIT-

Re: [algogeeks] Graphs.

2010-07-10 Thread Amit Jaspal
@ jalaj consider a graph 2->1 3->1 2->3 apply dfs(1) n dfs(2)... will give u 2 components although GRAPH is connected On Fri, Jul 9, 2010 at 10:23 PM, jalaj jaiswal wrote: > > int count=0; > for every vertex v{ > if visited[v]==0 > dfs(v) > count++; > } > count

Re: [algogeeks] Array Reconstruction

2010-07-09 Thread Amit Jaspal
nice approach Ashishthkz On Fri, Jul 9, 2010 at 11:14 AM, Ashish Goel wrote: > a minor correction > >> nC2 possibilities >> >> so n can be found using nC2=say6 then n=4 >> >> >> a+b=p0 >> a+c=p1 >> a+d=p2 >> b+c=p3 >> b+d=p4 >> c+d=p5 >> >> 3a+b+c+d=po+p1+p2 >> b+c+d=(p3+p4+p5)/2 >> >> so a=

Re: [algogeeks] Re: adobe problem---array

2010-07-08 Thread Amit Jaspal
Then do a inplace merge sort / a quick sort and then get a number which repeats 3 times On Thu, Jul 8, 2010 at 7:16 PM, jalaj jaiswal wrote: > @ any solution less then nlogn would do + O(1) space > > > On Thu, Jul 8, 2010 at 12:38 AM, souravsain wrote: > >> @jalaj >> >> Are we looking for a bett

Re: [algogeeks] Longest palindrome in a given str (less than O(n^2) )

2010-07-07 Thread Amit Jaspal
I don't understand how to constuct the suffix tree in less than O(n^2) can anyone explain me this? On Tue, Jul 6, 2010 at 10:03 AM, Jitendra Kushwaha wrote: > @Ankit Narang > Think about your algo it is not a O(n). First of all you wont get > solution comparing start of str1 and end of str2 >

Re: [algogeeks] Yahoo

2010-07-04 Thread Amit Jaspal
it will be 1:1 On Sun, Jul 4, 2010 at 4:50 PM, Jitendra Kushwaha wrote: > it will be half... > > > On Sun, Jul 4, 2010 at 4:18 PM, Piyush Verma <114piy...@gmail.com> wrote: > >> In a village in each family they give birth to children till they >> get a boy. IF girl child they try again. What is t

Re: [algogeeks] google favourite ques

2010-07-03 Thread Amit Jaspal
Thanks Ashish for this wonderful postI must say many of my doubts regarding networking were cleared And I will highly appreciate if any one can add on to this wonderful post by ashish.. On Sat, Jul 3, 2010 at 10:42 PM, ashish agarwal < ashish.cooldude...@gmail.com> wrote: > ur browser is

Re: [algogeeks] Diameter of a set of points

2010-06-28 Thread Amit Jaspal
@ above can u specify how to apply binary search here as the points are not in increasing manner...or am i missin something On Sun, Jun 27, 2010 at 9:43 PM, Amir hossein Shahriari < amir.hossein.shahri...@gmail.com> wrote: > it's obvious that these 2 points must be on the convex hull > so fir

Re: [algogeeks] arrays

2010-06-27 Thread Amit Jaspal
This is the famous Inversion Problem Hint: you can do it in O(nlogn) using a tweek in merge sort On Sun, Jun 27, 2010 at 11:26 AM, Anil C R wrote: > this is just brute force: > > count = 0 > for i in range(0, len(A)): > for j in range(i+1, len(A)): > if A[i] > A[j]: >

Re: [algogeeks] Re: sum k in sub array

2010-06-26 Thread Amit Jaspal
Srry i wrote wrongly i will store C[i] if C[i]-K is not found in BST.if found there is a sub array.. So now dry run... C[]=6,-1,7. K=7. And Yeah we will have to build a balanced BST for sure.. On Sun, Jun 27, 2010 at 1:57 AM, Dhritiman Das wrote: > > @amit: Need to store indices also in the tree

Re: [algogeeks] sort

2010-06-25 Thread Amit Jaspal
Put the numbers in the BST. Update the frequency. Print the numbers with Inorder Traversal. Height of Bst will be O(log(logn)). On Fri, Jun 25, 2010 at 5:51 PM, sharad kumar wrote: > You are given an unordered sequence of n integers with many duplications, > such that the number of distinct integ

Re: [algogeeks] Re: getting smallest 1 million numbers....

2010-06-24 Thread Amit Jaspal
@ above can u plz specify how to sort a 1 Tb file with 64 bytes of Ram. I got this heap methodbut ur approach seems interesting ..if u can give some links dat wud be very appreciated.. On Thu, Jun 24, 2010 at 1:01 AM, Douglas Diniz wrote: > If you have a memory that has less than 1 milli

Re: [algogeeks] Find the next number for a given number without using any arithmetic operators(use bit operations)

2010-06-24 Thread Amit Jaspal
#include #include int main() { int i=0,j; int n; scanf("%d",&n); for(i=0;i<31;i++){ if(!((1< wrote: > Find the next number for a given number without using any arithmetic > operators(use bit operations) > > -- > You received this message because you are subscribed to the Google Groups

Re: [algogeeks] sum k in sub array

2010-06-22 Thread Amit Jaspal
Let A[] be a array. Step 1: Find Cumulative Sum array say C[] if A[]={2,-1,3,5,6,-7,8} C[]={0,2,1,4,9,15,18,16} Now traverse through this C[] and keep storing C[i] in a BST. Whenever C[j]-C[i] = K (We have found our needed subarray) So for every element of C[] chk if C[i]-K is found in BST . If n

Re: [algogeeks] Re: Swap the bits

2010-06-21 Thread Amit Jaspal
@ Dave would u plz bother to discuss how do u arrive at this formula? On Mon, Jun 21, 2010 at 10:11 PM, Dave wrote: > Not hard at all: > > y = ((x & 0xAA) >> 1) | ((x & 0x55) << 1) > > Dave > > On Jun 21, 7:07 am, amit wrote: > > Given a byte, write a code to swap every two bits. [Using bit > >

Re: [algogeeks] max of 2 numbers

2010-06-20 Thread Amit Jaspal
@ above > , ? operators are not allowed. @ anand can u please explain how this works max=x + ( ( x - y ) & ( ( x - y ) >> 31 )) On Sun, Jun 20, 2010 at 1:16 PM, anand verma wrote: > max=x + ( ( x - y ) & ( ( x - y ) >> 31 )) > > -- > You received this message because you are subscribed to the

Re: [algogeeks] Re: Variant Of Dutch National Flag Problem

2010-06-19 Thread Amit Jaspal
I think radix sort will do. On Sat, Jun 19, 2010 at 6:03 PM, manisha nandal wrote: > this is not d final solution, trying to find a way > > 3B, 1R, 4Y, 2R, 5B, 7Y > > 1) Find max no. in the array i.e 7 > max=7 > > 2) assign values as R= max B=2*max Y=3*max > i.e R=7 B=14 R=21 > > 3) 3B = 3 +

Re: [algogeeks] OS problems

2010-06-19 Thread Amit Jaspal
@ above The heap getting exhausted is with respect to 1 Process only naa. i.e What I am trying to ask is Heap Section of Memory is seperate for all processes or Same? So when u say that heap gets exhausted no more dynamic memory can be allocated by that process or any other process in the system a

Re: [algogeeks] OS problems

2010-06-19 Thread Amit Jaspal
@ above I think it is because of the heap size . The Heap corresponding to dynamic memory allocation grows and merges with the stack section of the process. Correct me if I am wrong. And if was only because of calloc() , then will malloc work? Can we allocate 1gb dynamically using malloc()?? O

Re: [algogeeks] Re: Variant Of Dutch National Flag Problem

2010-06-18 Thread Amit Jaspal
@ above We have to do this inplace. On Fri, Jun 18, 2010 at 10:30 AM, Gaurav Singh wrote: > You may apply Radix sort here. > Sort on the basis of color first and then apply stable sort on the > digits. So on the whole you will be applying radix sort. > > -- > You received this message because yo

Re: [algogeeks] OS problems

2010-06-18 Thread Amit Jaspal
It means the program crashed while it was trying to allocate more memory . Now can u guess why that happened? On Fri, Jun 18, 2010 at 1:29 PM, jaladhi dave wrote: > can you explain what you meant when you said "the program fails after > allocationg about 800mg(appx. i dont remember). > This is th

Re: [algogeeks] Stack Space for Quick Sort vs Merge Sort.

2010-06-15 Thread Amit Jaspal
But what about the Stack Space Used while doing Merge and Quick Sort? On Mon, Jun 14, 2010 at 9:30 AM, Anurag Sharma wrote: > Seems correct to me :) > > Anurag Sharma > > > > On Sun, Jun 13, 2010 at 11:23 PM, amit wrote: > >> Can anyone tell what is Stack Space required for Quick Sort and Merge

Re: [algogeeks] sum to x

2010-06-11 Thread Amit Jaspal
I think we can use a Linked List. Sort it and then find numbers adding upto x. On Fri, Jun 11, 2010 at 9:39 PM, Raj N wrote: > @sharad: Does it have to return the first pair or all possible pairs ? > > > On Fri, Jun 11, 2010 at 6:56 PM, sharad wrote: > >> Given a large file, having N (N is very

Re: [algogeeks] Re: max sum

2010-06-11 Thread Amit Jaspal
Its DP i guess: recurrence relation is DP[i]=max(DP[i-1],a[i]+DP[i-2]); On Sat, Jun 12, 2010 at 12:13 AM, BALARUKESH wrote: > I hope using a backtracking solution suits the problem well... > maxsum( int arr[] , int n,int i,int sum, int last) > { > if(i { >int s1= 0,s2= 0,s3; >if(last ==

Re: [algogeeks] matix flipping

2010-06-07 Thread Amit Jaspal
#include using namespace std; int main(){ int a[4][4]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; int i=0,j,n=3,l=0,m=n; j=n; while(i<=n){ int i1=i,j1=j,k=0,l=n; for(;k wrote: > write a c routine to flip an nXn matrix about its non major diagnol > > > 3 4

Re: [algogeeks] Longest Increasing Subsequence in O(nlogn)

2010-05-28 Thread Amit Jaspal
I suppose the heading of the mail makes it clear , if its not i m takin about Longest Increasing Subsequence in O(nlogn) On Fri, May 28, 2010 at 9:49 PM, Anand wrote: > Hi Amit, > > Could you just elaborate which algorithm are you talking about. Is it KMP > algorithm for string matching are look