[algogeeks] Re: convert into palindrome

2012-01-02 Thread top coder
, 2011 at 4:26 AM, atul anand atul.87fri...@gmail.com wrote: Ignore my previous comment On 16 Dec 2011 17:35, atul anand atul.87fri...@gmail.com wrote: @All : can't we use Levenshtein algorithm to find min addition/deletion.?? On Fri, Dec 16, 2011 at 2:50 PM, top coder topcode

[algogeeks] Re: Longest sequence of numbers with atmost diff K

2012-01-02 Thread top coder
@Lucifer In your algo: how do we get the starting index of the subarray i.e result? On Jan 1, 11:03 pm, Lucifer sourabhd2...@gmail.com wrote: @atul.. Below i have explained how the reduction from N^2 to N log N approach will work.. Space complexity 2*N = O(N) The following data

[algogeeks] Find the path in two nodes of a binary search tree

2012-01-02 Thread top coder
Suppose you have a tree. A binary tree (for something like simplicity :p). You are traversing it (using infix, postfix or prefix) to search for a node. You find your required node. You just realized that you need to know the path from this node back to the root node (and/or vice versa). Given the

[algogeeks] Re: Determine if BST has single child for every node given pre order

2011-12-31 Thread top coder
Nice Solution and explanation Lucifer :) On Dec 31, 4:48 pm, Lucifer sourabhd2...@gmail.com wrote: @atul.. Yup.. exactly.. i think the problem is itself about narrowing the range and works really well as each node can have only one child.. :) On 31 Dec, 13:09, atul anand

[algogeeks] Divide the Square into 2 parts

2011-12-31 Thread top coder
Within a 2D space, there is a batch of points(no duplicate) in the region (0,0),(0,1),(1,0),(1,1), try to find a line which can divide the region to 2 parts with half points in each .the input will be an array of points and the length of the array. struct point{ int x; int y; }; input :

[algogeeks] Re: Determine if BST has single child for every node given pre order

2011-12-30 Thread top coder
= mid;    }    else       break; } if ( i == N)   printf (YES); else   print(NO); On 30 Dec, 12:51, top coder topcode...@gmail.com wrote: Input : You have been given a sequence of integers.  Now without actually constructing BST from the given sequence of integers

[algogeeks] Determine if BST has single child for every node given pre order

2011-12-29 Thread top coder
Input : You have been given a sequence of integers. Now without actually constructing BST from the given sequence of integers (assuming the sequence is pre-order) determine if each node of BST has single child (either left or right but not both). Output : YES if given integer sequence

[algogeeks] how many times you can write that word using subsets of the string

2011-12-28 Thread top coder
Given a long string and a given word find out how many times you can write that word using subsets of the string. (i.e., you can create dog with doom dogged 8 times. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send

[algogeeks] Re: how many times you can write that word using subsets of the string

2011-12-28 Thread top coder
Does your algo will take of repeated elements? In the above example there are 2 d's and 3 o's and 2 d's and hence it is resulting in 2x2x2 = 8 times dog On Dec 28, 3:58 pm, Lucifer sourabhd2...@gmail.com wrote: @1.. A recursive app shall do... @2 Isn't this problem similar to LCS problem

[algogeeks] Re: how many times you can write that word using subsets of the string

2011-12-28 Thread top coder
@Lucifer Your solution works :) On Dec 29, 2:41 am, Lucifer sourabhd2...@gmail.com wrote: @topcoder The above given algo takes care of repeated elements.. Let me know if u find a test case where its failing.. On Dec 29, 12:47 am, Tamanna Afroze afroze...@gmail.com wrote: This is

[algogeeks] Obstacle Avoidance

2011-12-28 Thread top coder
Given an n x n grid with a person and obstacles, how would you find a path for the person to a particular destination? The person is permitted to move left, right, up, and down -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

[algogeeks] Re: number of form m^n

2011-12-27 Thread top coder
Hello Sid Your code is working for N=4,8 but failing when N=9 9 is expressed as 3^2 but your code is giving output as :Not possible. On Dec 26, 9:36 pm, sid1 siddhantkhann...@gmail.com wrote: This algorithm won't work as primes might have different power. for eg. N=12 12 is divisible by 2

[algogeeks] Longest sequence of numbers with atmost diff K

2011-12-27 Thread top coder
Find the longest continuous subsequence of numbers in an unsorted array such that difference between any two nos. in that sequence should not be more than K. For example: 2,1,8,12, 10,15, 13, 25 and k=7 8,12,10,15,13 is the sequence (15-8=7) -- You received this message because you are

[algogeeks] number of form m^n

2011-12-26 Thread top coder
give an algorithm to find if a given integer is of the form m^n where m 1 and n 1 One Approach I can think of is to find prime factors and verify if they are of the form m^n -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

[algogeeks] Re: number of form m^n

2011-12-26 Thread top coder
Hello Samm I got your approach It seems it is not working for some of the examples Eg: N = 6 6 = 2X3 = 1X6 and hence it is not possible but your code prints Yes possible. On Dec 26, 9:03 pm, SAMMM somnath.nit...@gmail.com wrote: From Wht I can understand from problm to check whether N can

[algogeeks] Re: Frequency Sort Algo

2011-12-25 Thread top coder
What about the case of the numbers having same frequency? Which one should come first? On Dec 24, 11:18 pm, atul anand atul.87fri...@gmail.com wrote: first sort the given array , you will get 1,1,1,1,2,2,2,3,3,3,3,3,4,4,5 now count frequency of each number and insert it into min heap. each

[algogeeks] Longest Contiguous Subarray with average = k

2011-12-24 Thread top coder
Consider an array of N integers. Find the longest contiguous subarray so that the average of its elements is greater than a given number k I know the general brute force solution in O(N^2). Is there any efficient solution using extra space? -- You received this message because you are

[algogeeks] Re: convert into palindrome

2011-12-16 Thread top coder
, 2 additions would be required to convert it into a palindrome.. The possible palindromes would be: for NIN : N + AT + I(TA)N = NATITAN for NAN : N + TI+ A(IT)N = NATITAN On Dec 15, 11:24 am, top coder topcode...@gmail.com wrote: @Mohit Suppose for example String: NITAN

[algogeeks] Re: zig zag problem

2011-12-15 Thread top coder
int LIDS ( vectorint a , int n ){ int s[51][2]; for(int i = 0 ; i n ; i++) for(int j = 0 ; j 2 ; j++) s[i][j] = 1; for(int i = 0 ; i n ; i++){ for(int j = 0 ; j i ; j++){ if( a[i] != a[j] ){ s[i][a[i]a[j]] =

[algogeeks] convert into palindrome

2011-12-14 Thread top coder
Given a word, convert it into a palindrome with minimum addition of letters to it. letters can be added anywhere in the word. . for eg if hello is given, result should be hellolleh -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to

[algogeeks] Re: convert into palindrome

2011-12-14 Thread top coder
: Find the LCS of string with its reverse On Wed, Dec 14, 2011 at 8:33 PM, top coder topcode...@gmail.com wrote: Given a word, convert it into a palindrome with minimum addition of letters to it. letters can be added anywhere in the word. . for eg if hello is given, result should

[algogeeks] Re: Removing same character(s) in a group

2011-12-13 Thread top coder
();     if(val == str[i])     {             i++;     } } if(isDequeueEmpty()) {       //we know that from start to i is a repeated substr and should be removed. } On Mon, Dec 12, 2011 at 7:52 PM, top coder topcode...@gmail.com wrote: For example if aabbabc is given as input after first

[algogeeks] find numbers if pair wise sums are given

2011-12-13 Thread top coder
If pairwise sums of 'n' numbers are given in non-decreasing order identify the individual numbers. If the sum is corrupted print -1 Example: i/p: 4 4 5 7 10 12 13 o/p: 1 3 4 9 -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this