ow;
> head=ptr;
> }
> ptr->next->next=follow;
> if(follow!=NULL)
> follow->next->next=NULL;
> }
>
> @ankur: if odd number of nodes then maybe just ask interviewer how he
> wants it to be and try including that case ;)
>
>
> }
>
> On Mon, Jan 2
wat if u have odd no of nodes
On Tue, Jan 24, 2012 at 12:00 AM, atul anand wrote:
> one simple way would be using stacks.
> push node,node->next;
> then pop() , and reversing the pointers.
>
> On Mon, Jan 23, 2012 at 11:46 PM, Ankur Garg wrote:
>
>> Say LL is
&
Say LL is
1->2->3->4->5->6->7->8
Then u need to return
7->8->5->6->3->4->1->2
U cant swap the values U have to rearrange the ptr...
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googleg
Hello
I was going through this link
http://www.geeksforgeeks.org/archives/3187
Wonder what is the time complexity for this..?Can anyone explain >
Regards
Ankur
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send em
XOR Linked Lists
On Sat, Jan 14, 2012 at 7:06 PM, Ashish Goel wrote:
> design a linked list that has only one pointer per node yet can be
> traversed in forward or reverse direction.
>
>
> Best Regards
> Ashish Goel
> "Think positive and find fuel in failure"
> +919985813081
> +919966006652
>
>
think. Because it is avriable length
>>> encoding scheme.
>>>
>>> On Fri, Jan 13, 2012 at 11:11 AM, b.kisha...@gmail.com <
>>> b.kisha...@gmail.com> wrote:
>>>
>>>> Is there anything called in-place reversal ??
>>>> UTF-8 is
How to do this
Write a function to reverse a UTF-8 encoded string in-place ??
--
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
alg
@Lucifer
I am not getting how u r working with heapifying each time ..
Initially the array is such that minimum value is ay (0,0) and and max at
index (m-1,n-1)
Now when u swap a value
Then u heapify i.e. make the prior arrangement again but that in turn will
lead to few swaps and so on...(Recu
If we use K merge I think the time complexity would be nm lognm
I think we must try doing in O(m*n)
On Wed, Jan 11, 2012 at 1:54 PM, Ankur Garg wrote:
> @Shady Rows are already sorted ...
>
>
> On Wed, Jan 11, 2012 at 1:53 PM, shady wrote:
>
>> ^^ true, sort the rows a
@Shady Rows are already sorted ...
On Wed, Jan 11, 2012 at 1:53 PM, shady wrote:
> ^^ true, sort the rows and then a K-way merge.
>
>
> On Wed, Jan 11, 2012 at 1:00 PM, Sanjay Rajpal wrote:
>
>> I guess sort the array such that elements are sorted finally in such a
>> way that if we print them r
I think this wont work for cases with negetive nos
Ex
-2,8,-6
On Tue, Jan 10, 2012 at 6:51 AM, sravanreddy001 wrote:
>
> solution at this link:
> http://ideone.com/ifVIv
>
> for every position, (iteration)
> maitain left, right for the sums,
> keep adding elements towards the begenning to left,
Can you give an example
Say matrix is
1 1 0 0
1 1 0 0
0 0 1 1
Has it got 3 islands i.e 1-1 be in same row or they can be column wise also
i.e. 5
On Tue, Jan 10, 2012 at 7:09 AM, Ashish Goel wrote:
> there is a matrix of 1 and 0
> 1 is a island and 0 is water
> 1-1 together makes one island
@Priyanka ...Do the elements of the subarray need to be continuous ..The
example considers it continuous but still just for clarity ?
On Tue, Jan 10, 2012 at 12:50 AM, surender sanke wrote:
> using extra space of O(n) we can do it in O(n^2)
> take an array for storing cumulative sums from index i
sorry it shud be
sum of squares and xor and sumof elements
I think this shud work
Regards
Ankur
On Wed, Jan 4, 2012 at 9:52 PM, atul anand wrote:
> @ Karthikeyan :
>
> sum of cubes fails:-
>
> arr1={2,3,0,-3} = 4
> arr2={1,1,1,1} = 4
>
> On Wed, Jan 4, 2012 at 6:53 PM, Karthikeyan V.B wro
What if we check these 2 conditions
XOR and sum of elements and sizeof array same
I cudnt find any counter example
Regards
Ankur
On Wed, Jan 4, 2012 at 6:53 PM, Karthikeyan V.B wrote:
> Hi,
>
> Consider, arr1={1,2,3} and arr2={-1,-2,-3}
>
> using sum of squares method sum(arr1) = 14 ans sum
x.back()]-a[i])>k))
index.pop_back();
}
For the second part that you said , yes potentially if we use queue.size()
we can miss out on continuous part ..
Thanks for pointing these out
Regards
Ankur
On Tue, Jan 3, 2012 at 4:06 AM, Ankur Garg wrote:
> @Lucifer
>
> I checked with my code
>
&g
@Lucifer
I checked with my code
The answer is coming out to be 4 ..So in this case its passing
Also the queue is containing the indexes in order of increasing values ..so
for curr min we need to only check the front of the queue.
Also I remove the elements of the queue till all the diff of elem
I think this can be solved in NlogN using binary search
Here is the idea
We take a deque which stores the index of the array in increasing order
i.e. the index with minimum value is always on the front of the deque
Now when a new element comes we check with the front of this deque .
If the dif
Dude please ask these question on Interviewstreet group..
Your queries will be answered there
Kindly adhere to the protocols of this group..
This may be one off thing but it can lead to start of interview queries.So
please understand :)
On Thu, Dec 29, 2011 at 12:35 AM, Jyoti Malik wrote:
ite 4,4 to array.
> >
> > for node 2
> > frequency = 3
> > number =2
> >
> > write 2,2,2 to the given array...
> >
> >
> >
> > On Sat, Dec 24, 2011 at 10:57 PM, Ankur Garg
> wrote:
> > > how can one do frequency sort
@Atul..your solution is correct and would do the job but its complexity wud
be nlogn .
Any better way of solving it ?
Regards
Ankur
On Sun, Dec 25, 2011 at 2:10 AM, sravanreddy001 wrote:
> any better approach than O(N log N) time?
>
> maintain a heap of nodes
> for each element, if already pre
how can one do frequency sort .
Suppose we have an integer array like
1,2,3,1,2,3,1,1,2,3,4,4,3,5,3
Then 1 is appearing 4 times
2 - 3
3- 5
4-2
5-1
Then if we sort by frequency we shud have this as result
5,4,4,2,2,2,1,1,1,1,3,3,3,3,3
How to do it
--
Y
The thing is ..will it ascertain that the probability is equal
I am not sure how ur method guarantees that...
May be if you and Dave can explain the algo a bit better that wud be great .
regards
Ankur
On Sat, Dec 24, 2011 at 5:48 AM, Piyush Kansal wrote:
> Hey Ankur,
>
> What is the order of ti
Suggest an algo with which u can find a random node in an infinitely long
linked list
--
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
A better representation for a n-ary tree would be
struct node{
int data;
node* left;
node* sibling;
}
Like in a binary tree the second ptr points to its right child . Here it
points to its sibling.This one saves space and also We know in each level
we have how many nodes
@Shashank,
I th
ent pointing to its child
> , it would be child pointing to its parent after reversing
> i guess thats wat he is trying to say.
>
>
> On Tue, Dec 20, 2011 at 11:38 PM, Ankur Garg wrote:
>
>> Hey Shashank
>>
>> Unfortunately I cudnt understand the problem
>
Hey Shashank
Unfortunately I cudnt understand the problem
What do u mean by reversing the tree here :(..
On Tue, Dec 20, 2011 at 11:23 PM, WgpShashank wrote:
> here is my code
>
>
> List list=new LinkeList();
>
> public List reverseTreeandReturnListContainingAllLeafNOdes(Node n)
> {
>in
Hi
Can anyone help me with this question
Code for Serializing and Deserializing a binary Tree
--
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, s
as 4 whereas in the answer
should be 3
Regards
Ankur
On Mon, Dec 19, 2011 at 1:16 AM, Ankur Garg wrote:
> a linear solution for this problem . although its more than O(n) but will
> never be O(n*2)..used DP to solve it
>
> space used -O(2n)
>
> int ZigZagLength(vector
a linear solution for this problem . although its more than O(n) but will
never be O(n*2)..used DP to solve it
space used -O(2n)
int ZigZagLength(vector a){
int n=a.size();
int DP[n][2];
DP[0][0]=1;
DP[0][1]=0;
DP[1][0]=2;
DP[1][1]=0;
int j;
for(int i=2;i0){
if((a[i]-a[j])*(a[j]-a[DP[j][1]])<0){
suggest algo to find k most frequently occuring numbers from a file of very
large size containing numbers.
--
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 th
I saw this term "non-decreasing order"
So we need to sort the numbers first..it will take nlogn .
On Fri, Dec 16, 2011 at 1:12 AM, Ankur Garg wrote:
> on above algo , there is no need to calculate sum of array so we can do it
> in O(N) and not O(n).
>
>
> On Fri, Dec 16
on above algo , there is no need to calculate sum of array so we can do it
in O(N) and not O(n).
On Fri, Dec 16, 2011 at 12:59 AM, Ankur Garg wrote:
> Hi Topcoder.
>
> First of all you posted the wrong array .
>
> The array should be
>
> 4, 5, 10, 7,
Hi Topcoder.
First of all you posted the wrong array .
The array should be
4, 5, 10, 7, 12, 13
a+b a+c a+d b+cb+d c+d
Now first calculate a+b+c+d which will be (sumofarray)/N-1
So here a+b+c+d = 17
Now take a[1] is a+c
and a[N-1] = b+c
subtracting them giv
Twisted linked list problem: Two linked lists merge at some node p,both the
head pointers are given find the merging point under
the following restrictions.
1. You should not traverse to the end any of the linked list.
2. Merge node p should be detected by the time you reach at most most k
nodes fr
Given an array-based heap on n elements and a real number x, efficiently
determine whether the kth smallest element in the heap is greater than or
equal to x. Your algorithm should be O(k) in the worst-case, independent of
the size of the heap.
This question was also asked in Amazon
--
You rece
By Max Heapify I thought u meant to say u are making a Max Heap .. In case
you use Coreman Definition Of max Heapify it just heapifies assuming the
heap has been formed, But u need to make a max Heap first dude :)
P.S-> Clarify your concepts before posting the link :(
On Tue, Dec 13, 2011 at 12:1
Max Heapify is O(n).
On Mon, Dec 12, 2011 at 11:43 PM, ankit gupta wrote:
> apply MAXHEAPIFY on root ode and extract the root node
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@go
Agree with dave..Its still O(n)
On Mon, Dec 12, 2011 at 10:57 PM, Dave wrote:
> @Sagar: Don is correct. n/2+n/4+n/8+... ~= n. But even the first
> round, involving n/2 comparisons, is O(n).
>
> Dave
>
> On Dec 12, 11:23 am, sagar pareek wrote:
> > Yes Mr. DoN
> >
> > First round of Tournament s
> of action..
>
> On Thu, Dec 8, 2011 at 6:27 PM, Ankur Garg wrote:
>
>> Can we detect if a loop is present in Linked List if only head ptr is
>> given
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorith
Can we detect if a loop is present in Linked List if only head ptr is given
--
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
algoge
cWas it offcampus or on campus recruitment dude.
On Sat, Dec 3, 2011 at 12:5i7 PM, atul anand wrote:
> @payal : last problem is a dutch flag problem.
>
>
> On Sat, Dec 3, 2011 at 3:33 AM, payal gupta wrote:
>
>> congrats..:):)
>> plzz...elaborate the last two problemsand it vud be very grate
ich is nothing but,
> F(12, 3) = MAX
> {
> 1/2 + F(10, 2) ,
> 2/3 + F(9, 2) ,
> 2/4 + F(8, 2) , // this will yield the
> maximum sum..
> 3/5 + F(7, 2) ,
>
:
> >
> >
> >
> >
> >
> >
> >
> > > Optimal split: [0,0][1,1][0,0][1,1][0,1][1,0]
> > > Expected value of optimal split: 0 + 1 + 0 + 1 + 1/2 + 1/2 = 3
> > > why this is not the optimal split???
> >
> > > On Sun, Nov 27,
>
> S = empty
> while i = input item existss
> if i in S output "i has a duplicate";
> insert i in S
> end
>
> XOR is generally useful only for detecting a single item that's
> included in a list an odd number of times rather than an even number
> of times.
&
You have an array with *n* elements. The elements are either 0 or 1. You
want to *split the array into kcontiguous subarrays*. The size of each
subarray can vary between ceil(n/2k) and floor(3n/2k). You can assume that
k << n. After you split the array into k subarrays. One element of each
subarray
^^+1..how matrix formed ??
But as Gene said we can use a set to store all the unique elements
Now we xor all the set elements and then xor them with the elements of the
array . This wud give us the repeating element as all the elements coming
once will be 0(xored twice) and repeating element wud b
:(
On Fri, Nov 25, 2011 at 12:57 AM, Ankur Garg wrote:
> As it seems to me this can be solved like this
>
> Find LCA(Least common ancestor) of node x and z .. See if it equals y or
> not . If not recursively search for y in left and right subtree of LCA ..If
> you find y in the
As it seems to me this can be solved like this
Find LCA(Least common ancestor) of node x and z .. See if it equals y or
not . If not recursively search for y in left and right subtree of LCA ..If
you find y in the descendents of LCA answer is true else its false .
This method will give perfect an
t; > while (p > 0 && stk[p - 1] >= in) p--; // pop
> > a[i] = (p > 0) ? stk[p - 1] : 0;
> > stk[p++] = in; // push
> > }
> >
> > }
> >
> > On Nov 23, 5:13 am, Ankur Garg wrote:
> >
> >
> >
> > > Solutio
p.second]=0;
}
}
On Wed, Nov 23, 2011 at 3:43 PM, Ankur Garg wrote:
> Solution given by tech coder is fine and is working .. I coded it and its
> working perfectly using stack
>
>
>
> On Wed, Nov 23, 2011 at 2:50 PM, Gene wrote:
>
>> It's a nice problem, and this
Solution given by tech coder is fine and is working .. I coded it and its
working perfectly using stack
On Wed, Nov 23, 2011 at 2:50 PM, Gene wrote:
> It's a nice problem, and this solution is almost right.
>
> Process the input in _reverse_ order, which means we'll also generate
> output in r
I think Merge Sort doesnt require any swapping . So , for 3 my answer wud
be Merge Sort
On Mon, Nov 21, 2011 at 11:55 AM, Dave wrote:
> @Kumar: For question 1, the answer is radix sort. It doesn't use data
> comparisons at all.
>
> Dave
>
> On Nov 21, 12:04 am, kumar raja wrote:
> > if we have
a linked list contains
2 19 _ _ 3 47 _ _ _ 2 20 _ _ ..and so on
I have to fill those empty nodes with numbers whose sum is equal to the
numbers
occurring just before the gaps and the number of gaps is determined by the
node
which is at 2 distance before the gaps with the limitation that
Can u provide a pseudo code for the same and c if it works
On Thu, Nov 17, 2011 at 2:37 AM, sravanreddy001 wrote:
> Start with counting sort of the input.
> Use shuffling algorithm on it.
>
> Store index as cumulative sums of counts.
>
> --
> You received this message because you are subscribed
Given a string of lowercase characters, reorder them such that the same
characters are at least distance d from each other.
Input: { a, b, b }, distance = 2
Output: { b, a, b }
How to approach this question ?
--
You received this message because you are subscribed to the Google Groups
"Algorit
Radix Sort
On Mon, Nov 14, 2011 at 1:57 PM, Vijay Khandar wrote:
> Which is the sorting algm sorts the integers [1...n^3] in
> O(n).
> a)Heapsort
> b)Quicksort
> c)Mergesort
> d)Radix sort
>
> please tell anyone.
> Vijay.
>
> --
> You received this message becaus
We can use a trie here .. Create a trie with all words of dictionary .
Now delete the last character of the word and check if such a word is a
valid word . If not see if adding a new character can make it a valid word
. If not delete the next character and repeat the process again .
This is what
@Srinivas
Wat if the string is abc
then it reduces to cc :) ...So size 2 can also be there.so u cant say it
will be 1 "always"
On Sun, Nov 13, 2011 at 12:01 AM, Srinivasa Chaitanya T <
tschaitanya@gmail.com> wrote:
>
>
> On Sat, Nov 12, 2011 at 4:24 PM, Snoopy Me wrote:
>
>> Given a string
Well it aint O(n) ..:P ...The erase part will be complex and will take
shifting string parts . So complexity will be O(n^2) for str.erase operation
On Sat, Nov 12, 2011 at 8:34 PM, Ankur Garg wrote:
> The Complexity of my solution is of Order n . At most I Traverse the whole
> string
The Complexity of my solution is of Order n . At most I Traverse the whole
string twice ..
On Sat, Nov 12, 2011 at 8:29 PM, vikas wrote:
> seems like quesion of permutation, it will take all the permutation to
> check which one can lead to answer, there will be always be more than
> one solutio
Hey I coded it . The answer is either 2 or 1 ..So I guess you guys are rite
:)
Here is the code
void smallestString(string &str){
if(str.empty()) return;
int j=0,i,k=0;
for(i=1;i0)j--;
i=j;
}
}
}
On Sat, Nov 12, 2011 at 8:19 PM, Nitin Garg wrote:
> If yes, how d
Did they ask you to code this or just asked logic
On Sat, Nov 12, 2011 at 4:57 PM, surender sanke wrote:
> @myself
>
> if number of distinct characters are equal then its final string size is 2.
> else there are more repeated characters other than distinct characters
> then its 1
>
> correct m
I think this can be solved like this .
Start from the first petrol pump i.e first point in the circle . Now if the
petrol finishes befor reaching the second petrol pump that means we chose
the incorrect point . So , choose second petrol pump now. If u reach third,
fill ur tanker and move to 4th . N
efficiently than
> computing the powers of any other number. Complexity in any case remains the
> same.
>
>
> On 24 October 2011 10:29, rahul sharma wrote:
>
>> +1 ankur
>>
>>
>> On Mon, Oct 24, 2011 at 1:26 AM, Ankur Garg wrote:
>>
>>> Use Binary S
Use Binary Search
start = 2^n-1 high =2^n where n=0,1
On Mon, Oct 24, 2011 at 12:28 AM, sunny agrawal wrote:
> hint 1: try to find 2 indexes i, j such that a[i] <= K <= a[j]
>
>
> On Sun, Oct 23, 2011 at 11:23 PM, Ankuj Gupta wrote:
>
>> Given a sorted array of Infinite size, find an elemen
if you are dealing with some very large arrays.
>
> Dan :-)
>
>
> On Oct 14, 9:44 pm, Ankur Garg wrote:
> > @Dan ..can you post the algo here or link to the book??
> > @Anika ...yes please post the code here..but please explain a bit about
> > underlying algo .
{You are given an unsorted array of integers. You have to find out the first
sub array whose elements when added sum up to zero.
eg:- int Array[] = {1,2,-4,-3, 6 ,-3.}Here sub array is -3,6,-3 bcos
adding all these sum to zero. A sub array can be of size 2 to whole length
of the array. You can
@Shashank ..+1 ..I wud say he must be given a tuning award :D :D for
solving such eternal conundrum ;)
On Mon, Oct 17, 2011 at 2:37 PM, WgpShashank wrote:
> @wladimir , its PPT (Pythagoras triplets ) but its number theory based
> approach http://en.wikipedia.org/wiki/Pythagorean_triple might
*Turing :P
On Mon, Oct 17, 2011 at 3:51 PM, Ankur Garg wrote:
> @Shashank ..+1 ..I wud say he must be given a tuning award :D :D for
> solving such eternal conundrum ;)
>
>
>
> On Mon, Oct 17, 2011 at 2:37 PM, WgpShashank
> wrote:
>
>> @wladimir , its PPT (Pythag
t,level+1,minL,maxR,left,right);
if(level<0)
left[abs(level)] +=root->data;
else
right[level] +=root->data;
}
On Sun, Oct 16, 2011 at 4:23 PM, Ankur Garg wrote:
> I am assuming we are allowed to use space ..With that i make 2 arrays 1 to
> store values from left side and oth
I am assuming we are allowed to use space ..With that i make 2 arrays 1 to
store values from left side and other from right side .
Here is the func
void getLevelSum(node* root,int &minL,int &maxR,int level){
if(!root) return ;
minL = min(minL,level);
maxR = max(maxR,level);
getLevelSum(root-
@Sunny ..Superb Algo ..but can you share some link where we can read abt it
:)..especially where the info abt the equation u used is given
Thanks in Advance
On Sat, Oct 15, 2011 at 12:37 PM, Kunal Patil wrote:
> @Sunny: Thanks for the info !! That's gr8..& your logic also seems to be
> workin
@Dan ..can you post the algo here or link to the book??
@Anika ...yes please post the code here..but please explain a bit about
underlying algo ...(algo is more important than actual code )
On Sat, Oct 15, 2011 at 1:54 AM, Dan wrote:
> On Oct 13, 7:52 pm, "shiva@Algo" wrote:
> > Convert an ar
not sure how it will work in O(n) time then.
>>
>> Thanks,
>> - Ravindra
>>
>>
>> On Fri, Oct 14, 2011 at 12:25 AM, Ankur Garg wrote:
>>
>>> @rahul...How do u choose z and x for computing z^2 -x^2 ?
>>>
>>> On Thu, Oct 13, 2011 at
@rahul...How do u choose z and x for computing z^2 -x^2 ?
On Thu, Oct 13, 2011 at 11:34 PM, rahul wrote:
> You can create a hash with sqrt(z2-x2). This will make it o(n). The
> interviewer just made it lil tricky. That's all
>
> --
> You received this message because you are subscribed to the Go
BTW can we solve this by hashing..That is the only feasible solution which
comes to my mind to reduce the time complexity ?
On Thu, Oct 13, 2011 at 11:20 PM, Ankur Garg wrote:
> Dude this is nothing but 3 sum problem
>
> http://en.wikipedia.org/wiki/3SUM
>
> Ask interviewer to
Dude this is nothing but 3 sum problem
http://en.wikipedia.org/wiki/3SUM
Ask interviewer to check this link and say he has gone mad!! :P
Regards
Ankur
On Thu, Oct 13, 2011 at 10:29 PM, ravindra patel
wrote:
> Hi,
> Another question I faced in Amazon F2F.
>
> Given an unsorted array of inte
oo much space..
> Balanced Binary tree can be Better ...??
>
>
> On Tue, Oct 11, 2011 at 12:16 AM, Ankur Garg wrote:
>
>> I think this can be done through tries
>>
>> Any better solution ?
>>
>> On Mon, Oct 10, 2011 at 10:59 PM, sachin goyal wrote:
>>
I think this can be done through tries
Any better solution ?
On Mon, Oct 10, 2011 at 10:59 PM, sachin goyal wrote:
> remove duplicate words from a string with min. complexityy.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To
Memoization ?
On Mon, Oct 10, 2011 at 6:34 PM, arvind kumar wrote:
> Can anyone tell me how to go about with the memorization technique to
> retrieve values from already stored values,in case of eveluating
> sequences(fibonacci series,etc).?
>
> --
> You received this message because you are sub
@Sravan ..Counting Sort takes O(n) time but it needs range of nos to be
known
@Snehi jain..there is no range given so am not sure if count sort will work
,Can you please elaborate a bit on ur method
Ankur
On Mon, Oct 10, 2011 at 10:09 PM, sravanreddy001
wrote:
> Just went throught what a count s
Given a 2D matrix which is both row wise and column wise sorted. Propose an
algorithm for finding the kth smallest element in it in least time
complexity
A General Max Heap can be used with k space and n+klogk complexity
Any other solution or even a way by which we dont scan the whole matrix to
Given an unsorted array of Integers
Find 2 nos whose diff is minimum
Say Array is 4 2 18 19 11 8 5
Nos are 18 and 19
Algo shud be of O(n)
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@goog
Is it sum of bits or sum of digits ?
On Sun, Oct 9, 2011 at 1:39 PM, wujin chen wrote:
> Given a positive number N, find a minimum number M greater than N, M has
> the same length with N and the sum of the bits are equal.
>
> example:
> N=134 , M=143, // 1+3+4=1+4+3
> N=020, M = 101, //2=1+1
>
Can anyone suggest a pseudocode handling rotations in an AVL tree for
deleting a node
I couldnt find one in the internet and was unable to derive a proper logic
which cud be transformed into code :(
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" g
+1
On Sun, Oct 9, 2011 at 2:07 AM, Sunny wrote:
> Now All of the messages are being Moderated and will be posted on the
> group only if they are found relevant, any irrelevant post be simply
> discarded without any notification till percentage of irrelevant posts
> reduces by a significant amoun
Hi ,
Can anyone think of any better for doing this other than converting into
List and then converting back again to BST ..
Regards
--
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.
To do inplace stack reversal u need a mechanism by which u can transfer the
first node to last of the stack making sure u have count of other nodes
here
Say u have stack
5<- top
4
3
2
1
The answer should generate the stack as
1-&s){
if(s.empty()) return;
temp=s.top();
s.pop();
Inpla
Implement recursive merge sort for first question
For second just swap the values of node and node b
On Wed, Oct 5, 2011 at 9:18 PM, 9ight coder <9ightco...@gmail.com> wrote:
> 1.perform inplace(we cant create new node)merge sort of two sorted
> linked list.(asked in amazon 1 mon before)
> 2.a
Find out the smallest segment in a document containing all the given words.
Desired Complexity is O nlogK ..n is the total no of words in the document
and k is the number of input words
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post
Code for Compression
I am doing it inplace
void convert(char* s,int len){
int i=0;
int count=1;
int index=1; //*maintain the index where number is to be added*
for(i=1;i<=len;i++){
if(s[i]==s[i-1])
count++;
else{
s[index-1]=s[i-1];*//put the cha
Keep an array to store multiplication of numbers like for input
9 3
U have to compute 9^9
So an array to store the digits and do simple multiplication like 9*9 will
give 81 so Array will have 81
then 81*9 729 ..so on
Then output the first k digits and last k digits of the array
Any1 having
Many times this problem has been discussed ..Please check the archives yaar
:(
On Mon, Oct 3, 2011 at 11:39 PM, Shruti Gupta wrote:
> I had inserted 0 instead of 1 The corrected code will be:
> public static void setZeros(int[][] matrix) {
>int[] row = new int[matrix.length];
>int[] col
--
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...@googlegroups.com.
For more options, visit this group at
ht
Committed to launch a website,formatting ..clarifying in case you mistook it
for somethin else :D
On Mon, Oct 3, 2011 at 7:50 PM, Ankur Garg wrote:
> Nice Idea but for pulling this you need committed people :)
>
> On Mon, Oct 3, 2011 at 7:36 PM, sukran dhawan wrote:
>
>> Hell
Nice Idea but for pulling this you need committed people :)
On Mon, Oct 3, 2011 at 7:36 PM, sukran dhawan wrote:
> Hello guys,
> Here is a suggestion.With so much talented people in this group,why cant we
> a website that is similar to geeksforgeeks.
> It will be really helpful to others if all t
Can u provide a proper HashMap
Not Implementation..A proper Idea wud do :)
On Mon, Oct 3, 2011 at 1:03 AM, Preetam Purbia wrote:
> you can implement using hashmap..
>
> On Mon, Oct 3, 2011 at 12:51 AM, Ankur Garg wrote:
>
>> Define a data structure , using extra memory
Define a data structure , using extra memory/space , such that :
Insert(int a)
Delete(int a)
isPresent(int a)
get(int a)
All above operations on the defined data structure take O(1) , i.e. constant
time.
--
You received this message because you are subscribed to the Google Groups
"Algor
@Rahul
Scan the matrix and whenver u see a[i][j]=0 put a[i]]0]=0 and a[0][j]=0
Meaning to say that put that row or column as 0
Now,
Scan the first row and first column and whereever u see a 0 make that column
and row 0 respectively
Eg
1 1 1 1
0 1 0 1
1 1 1 0
Answer shud be
0 1 0 0
0 0 0 0
0
1 - 100 of 182 matches
Mail list logo