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 f
@Lucifer
In your algo: how do we get the starting index of the subarray i.e
result?
On Jan 1, 11:03 pm, Lucifer 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 structures will be use
tr(x i+1)..."
>
>
>
>
>
> On Fri, Dec 16, 2011 at 4:26 AM, atul anand wrote:
> > Ignore my previous comment
>
> > On 16 Dec 2011 17:35, "atul anand" wrote:
>
> > > @All : can't we use Levenshtein algorithm to find min
> > addi
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 : struct
Nice Solution and explanation Lucifer :)
On Dec 31, 4:48 pm, Lucifer 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 wrote:
>
>
>
> > ok so by doing ri
> > {
> > if (A[i] <= mid && A[i] > left)
> > {
> > mid = A[i];
> > right = mid;
> > }
> > else if (A[i] > mid && A[i] <= right)
> > {
> > mid = A[i];
> > left = mid;
> > }
> &g
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 corresponds
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 g
@Lucifer
Your solution works :)
On Dec 29, 2:41 am, Lucifer 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 wrote:
>
>
>
> > This is really an interesting problem. If it
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 wrote:
> @1..
> A recursive app shall do...
>
> @2
> Isn't this problem similar to LCS problem where the constrain
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, s
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 subscrib
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 wrote:
> This algorithm won't work as primes might have different power. for
> eg. N=12
>
> 12 is divisible by 2 so it ends up being 3.
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 wrote:
> From Wht I can understand from problm to check whether N can be
> expressed a m^n :
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 g
What about the case of the numbers having same frequency?
Which one should come first?
On Dec 24, 11:18 pm, atul anand 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 node contain 2 var
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 subscribed
t; Here all we care about the count which is 2. Hence, 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
>
int LIDS ( vector 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]] = max(s[j][a[i]a[j
t;NITATIN" ...?
>
> > On Wed, Dec 14, 2011 at 8:39 PM, saurabh singh wrote:
> > > Find the LCS of string with its reverse
>
> > > On Wed, Dec 14, 2011 at 8:33 PM, top coder wrote:
>
> > >> Given a word, convert it into a pali
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 t
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 g
t; while ( dequeue() != NULL)
> {
> val=dequeue();
> if(val == str[i])
> {
> i++;
> }
>
> }
>
> if(isDequeueEmpty())
> {
> //we know that from start to i is a repeated substr and should be
> removed.
>
>
>
> }
> On
For example if aabbabc is given as input after first iteration, it
should be ababc and after that it should become abc. if aabbcabc is
given it should give abcabc after first interation, no change in
second iteration and abc after third iteration.
--
You received this message because you are subs
24 matches
Mail list logo