[algogeeks] Re: [Linkedlist] Given only a pointer to a node to be deleted in a singly linked list how you handle deleting last node

2012-07-11 Thread Mr.B
Even if assuming the allocation is uniform.
Knowing the address of previous node is the limitation on SLL in constant 
time.
Also, if we know the address of previous node. we are done. But, finding it 
will take O(n) time.

On Wednesday, 11 July 2012 03:36:46 UTC-4, invictus wrote:

 Well, we can do one thing but it might not work in all cases.

 First of all you need to know the node structure. Assume it has an int and 
 a next pointer.

 Assumption - Memory allocation for nodes did not happened at random 
 location but uniformly. 
 1. Find out the memory address contained in the next pointer of current 
 node. Compute the difference between address of current and next node.
 2. Compute the address for previous node (to check the above assumption, 
 figure out the address at memory for the next pointer is allocated, check 
 the contents of that pointer, if that content matches the memory location 
 of the current node address , then our above assumption was right.
 3. Now we have the address of the last node, copy the current node's data 
 in the last node and modify it's next pointer to point to current node's 
 next 
 we can also have a temporary pointer for recording the location of current 
 node and deleting it after step.3

 Hope the solution is clear.

 On Tuesday, 10 July 2012 01:36:17 UTC+5:30, subharansu wrote:

 Is there any solution which will take care deleting a node Given only a 
 pointer to a node to be deleted in a singly linked list( 
 *How Do we consider deleting the last node*) *
 *

 *Subhransu 
 *



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/2MBS7TD8_aAJ.
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.



[algogeeks] Re: Secure computation of Intersection of two sets

2012-07-10 Thread Mr.B
But again.. this can be reconstructed at the sever. taking first number and 
adding the differences.

On Monday, 9 July 2012 23:54:23 UTC-4, enchantress wrote:

 Give the first first number and set of cosecutive diffrence. 

 On Sunday, 8 July 2012 10:55:55 UTC+5:30, Sairam wrote:

 How do you find the intersection of two sets in a secured way? 
 Which means imagine a situation where there is a client  who has got a 
 set S1={1,2,3}, and there is a  server who has got a set S2[{2,3}. Client 
 wants to find the count of intersection which is |S1 intersection S2| = 2. 
 But, it doesn't want to give the set S1 directly to the server? How should 
 the client give the set S1, such that server computes the intersection of 
 S1 and S2 and gives the count to client.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/dklhSxUDXg0J.
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] Directi Interview Ques

2012-07-10 Thread Mr.B
I think you missed the question:
Its a stable merge. (order of elements in each array should be same)
Sorting will destroy the original order.

Thanks,
Mr.B
[Please include complexities and pseudo-code]

On Tuesday, 10 July 2012 16:18:04 UTC-4, Akshat wrote:

 Here you have to first sort both the arrays A and B and merge both the 
 arrays to form the sorted array C
  
 -- 


 Akshat Sapra
 Under Graduation(B.Tech)
 IIIT-Allahabad(Amethi Campus)
 *--*
 sapraaks...@gmail.com
 akshatsapr...@gmail.com
 rit20009008@ rit20009...@gmail.comiiita.ac.in


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/uCRLEzDBWAAJ.
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.



[algogeeks] Re: [Google] Finds all the elements that appear more than n/3 times

2012-07-10 Thread Mr.B
I found a similar solution looking somewhere else.

The solution for this problem is:
a. There can be atmost 3 elements (only 3 distinct elements with each 
repeating n/3 times) -- check for this and done. -- O(n) time.
b. There can be atmost 2 elements if not above case.

1. Find the median of the input. O(N)
2. Check if median element is repeated N/3 times or more -- O(n) - *{mark 
for output if yes}*
3. partition the array based on median found above. - O(n)  -- {partition 
is single step in quicksort}
4. find median in left partition from (3). - O(n)
5. check if median element is repeared n/3 times or more - O(n)  *{mark for 
output if yes}* 
6. find median in right partition from (3). - O(n)
7.  check if median element is repeared n/3 times or more - O(n)  *{mark 
for output if yes}*  

its 7*O(N) = O(N) solution. Constant space.

we need not check further down or recursively. {why? reason it.. its simple}


On Wednesday, 27 June 2012 18:35:12 UTC-4, Navin Kumar wrote:


 Design an algorithm that, given a list of n elements in an array, finds 
 all the elements that appear more than n/3 times in the list. The algorithm 
 should run in linear time

 ( n =0 ).

 You are expected to use comparisons and achieve linear time. No 
 hashing/excessive space/ and don't use standard linear time deterministic 
 selection algo.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/OYZtR1iwbGQJ.
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.



[algogeeks] Re: Directi question

2012-07-09 Thread Mr.B
There is a greedy solution discussion about this approach. I don't have a 
formal proof for this.
Any counter example will be helpful.

at every place 'k' .. do the following.

-- find max ( a[k+i]+i )  where 1 = i = a[i]

for the given example:
A = {4 0 0 3 6 5 4 7 1 0 1 2} 

initially a 4, the loop will be.
  0+1,0+2,3+3,6+4 -- 10 is max. jump to 6.
now at 6. (since, you can't reach end.)
5+1, 4+2, 7+3, 1+4, 0+5, 1 + 6, == 10 is max. jump to 7.
make another step. (but you can reach the end.) so jump to last.

this is greedy approach.. and a linear time soultion.

On Monday, 9 July 2012 09:32:08 UTC-4, Akshat wrote:

 Given an array A and the elements stored in an array denotes how much jump 
 an element can make from that array position. For example there is an array 
 A = {4 0 0 3 6 5 4 7 1 0 1 2}

 Now Ist element which is 4 can make a jump to element 0, 0, 3 and 6. You 
 are stuck if you end up at 0. 
 You have to output the minimum number of jumps that can be made from 
 starting position to end position of an array.

 -- 


 Akshat Sapra
 Under Graduation(B.Tech)
 IIIT-Allahabad(Amethi Campus)
 *--*
 sapraaks...@gmail.com
 akshatsapr...@gmail.com
 rit20009008@ rit20009...@gmail.comiiita.ac.in
  

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/QRWxd8B2DzcJ.
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.



[algogeeks] Re: Secure computation of Intersection of two sets

2012-07-09 Thread Mr.B
Properties of cryptographic hash functions will help.
so, sending a hash of a value is the best option.
as its nearly impossible to find a value for a given hash.

http://en.wikipedia.org/wiki/Cryptographic_hash_function#Properties 

both server and client using same hash function will solve this.

On Sunday, 8 July 2012 01:25:55 UTC-4, Sairam wrote:

 How do you find the intersection of two sets in a secured way? 
 Which means imagine a situation where there is a client  who has got a set 
 S1={1,2,3}, and there is a  server who has got a set S2[{2,3}. Client wants 
 to find the count of intersection which is |S1 intersection S2| = 2. But, 
 it doesn't want to give the set S1 directly to the server? How should the 
 client give the set S1, such that server computes the intersection of S1 
 and S2 and gives the count to client.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/WnD7OvJ1BQEJ.
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] Re: candies - interviewstreet -- how to go about solving this problem

2012-07-09 Thread Mr.B
a very good counter example. for the approach. even thought you didn't 
solve as per my solution.

(1 2 3 4 5 6 3 2) (6 9 10 12 6 5 4 3 2 1)
 
A small change to the original algorithm. The candies to max. element in 
each trivial array is
max(elements_before_it + 1 ,elements_after_it) + 1

And, start with 2 in each subarray except the first one, where we start 
with 1.
and.. keep increasing until max is reached. for the decreasing sequence. 
start with (number of elements in decreasing seq. and reach until 1.

(1 2 3 4 5 6 3 2) (6 9 10 12   6 5 4 3 2 1) 
 1 2 3 4 5 6 2 1   2 3  4 (5/7) 6 5 4 3 2 1

so, candies for 12 will be *max (3+1, 6) + 1*

 1 2 3 4 5 6 *2 1*   2 3  4 (5/7) 6 5 4 3 2 1 
you gave a wrong assignment as (5,4) instead of (2,1) underlined above. 
this was the point where your did a mistake with my solution.


On Monday, 9 July 2012 11:04:40 UTC-4, Bhaskar wrote:

 take a test case:
 1 2 3 4 5 6 3 2 6 9 10 12 6 5 4 3 2 1

 the subarrays then are:
 (1 2 3 4 5 6 3 2 ) (6 9 10 12 6 5 4 3 2 1)
  1 2 3 4 5 6 5 44 5  6   7  6 5 4 3 2 1  --candies allotment on 
 solving subarrays..
 
 here both are given same candies which is wrong !
 I mean that the subarrays solution are not independent!


 On Mon, Jul 9, 2012 at 3:58 PM, Anshu Mishra anshumishra6...@gmail.comwrote:

 @sanjay it's not like that

 e.g : (3 5 6 7 8 4) 7
 1 2 3 4 5 1  2 
 Yes we have to increase just by one, but while decreasing choose the 
 lowest possible such that each trivial component, if it is in decreasing 
 phase, should end with 1.
   
 On Mon, Jul 9, 2012 at 12:53 PM, sanjay pandey sanjaypandey...@gmail.com
  wrote:

 does ur sol seems lyk incerasing 1 if next number is greater that prev n 
 decreasing 1 if less..???

  -- 
 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 
 http://groups.google.com/group/algogeeks?hl=en.




 -- 
 Anshuman Mishra | Software Development Engineer | Amazon

  -- 
 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 
 http://groups.google.com/group/algogeeks?hl=en.




 -- 
 regards,
 Bhaskar Kushwaha
 Student
 Final year
 CSE
 M.N.N.I.T.  Allahabad



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/pGua7kg5LvUJ.
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] flipkart question

2012-07-09 Thread Mr.B
I was trying to solve this.. was somewhat close before I looked at ur 
solution.
But.. equal probability for 1-12 (1 inclusive is a good hint for putting on 
0's)

On Saturday, 7 July 2012 15:58:35 UTC-4, Abhishek Sharma wrote:

 @Raj: trace karke dekh na yaar when u have 3 0s and 3 6s.. the sum 
 distribution would look like this: 

 given below are the possibilities: 

 Combination of 1,2,3,4,5,6 with 0
 1+0 = 1
 2+0 = 2
 3+0 = 3   

 OR

 4+0 = 4
 5+0 = 5
 6+0 = 6

 Combination of 1,2,3,4,5,6 with 6

 1+6 = 7
 2+6 = 8
 3+6 = 9

 OR 

 4+6 = 10
 5+6 = 11
 6+6 = 12

 ho gye na evenly distribute :)

 On Sat, Jul 7, 2012 at 10:24 PM, Prakhar Jain jprakha...@gmail.comwrote:

 Label 3 of the faces with 0 and other 3 faces with 6.


 -- 
 Prakhar Jain
 IIIT Allahabad
 B.Tech IT 3rd Year
 Mob no: +91 9454992196
 E-mail: rit2009...@iiita.ac.in
   jprakha...@gmail.com



 On Sat, Jul 7, 2012 at 12:52 AM, Hraday Sharma hradaysha...@gmail.comwrote:

 You are given 2 dice. Both are fair. One of the dice has no numbers 
 printed on it. You have to label the unmarked dice such that when both the 
 dice are thrown, the sum on the faces is evenly distributed between 1 and 12
  .


  -- 
 You received this message because you are subscribed to the Google 
 Groups Algorithm Geeks group.
 To view this discussion on the web visit 
 https://groups.google.com/d/msg/algogeeks/-/uXBWN7DSu_gJ.
 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.


  -- 
 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 
 http://groups.google.com/group/algogeeks?hl=en.




-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/61mXOoD-EuoJ.
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.



[algogeeks] Re: [Linkedlist] Given only a pointer to a node to be deleted in a singly linked list how you handle deleting last node

2012-07-09 Thread Mr.B
The constant time removal of last node in a SLL is the limitation of 
approach you have in mind.
-- I read it in somewhere (may be Cracking Coding interview 4th edition)
if we have access to head.. then.. its the trivial O(n) time.


On Monday, 9 July 2012 16:06:17 UTC-4, subharansu wrote:

 Is there any solution which will take care deleting a node Given only a 
 pointer to a node to be deleted in a singly linked list( 
 *How Do we consider deleting the last node*) *
 *

 *Subhransu 
 *


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/a4A5kwf9X08J.
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.