There is a stream of numbers coming in and you have to find K largest
numbers out of the numbers received so far at any given time. Next problem
is that a constraint is added. memory is limited to m. m k. How would you
achieve the goal still.
--
You received this message because you are
Check this out. The first answer is the most efficient one. You find each
bit of the number, by using modulo operator.
http://stackoverflow.com/questions/9442958/find-the-element-occurring-b-times-in-an-an-array-of-size-nkb
On Wed, May 8, 2013 at 2:40 PM, Nishant Pandey
@ Jatin : N elements occur k times - there are N distinct elements and
total of N*k elements..
one element occurs b times - there are b elements and one distinct element
..
totally N+1 distinct elements and N*k + b elements are there ...
On Wed, May 8, 2013 at 1:14 AM, jatin luthra
i think u should utilize the property of XOR, this would help.
On Wed, May 8, 2013 at 12:02 AM, MAC macatad...@gmail.com wrote:
I was asked this in recent amazon onsite interview and asked o write code
Given an Array of integers . N elements occur k times and one element
occurs b times, in
N elements occur k times and one element occurs b times, in other words
there are n+1 distinct Elements
didn't get this statement
On Wed, May 8, 2013 at 12:02 AM, MAC macatad...@gmail.com wrote:
I was asked this in recent amazon onsite interview and asked o write code
Given an Array of
Are these n+1 elements range from 1 to n+1 ?
On Wed, May 8, 2013 at 12:02 AM, MAC macatad...@gmail.com wrote:
I was asked this in recent amazon onsite interview and asked o write code
Given an Array of integers . N elements occur k times and one element
occurs b times, in other words
I was asked this in recent amazon onsite interview and asked o write code
Given an Array of integers . N elements occur k times and one element
occurs b times, in other words there are n+1 distinct Elements. Given that 0
b k find the element occurring b times.
We know k is NOT even .
thanks
@wladimir yes the problem seems to be that!!
On Tue, Dec 11, 2012 at 10:13 AM, Wladimir Tavares wladimir...@gmail.comwrote:
subset sum?
Wladimir Araujo Tavares
*Federal University of Ceará http://lia.ufc.br/%7Ewladimir/
Homepage http://lia.ufc.br/%7Ewladimir/ |
subset sum?
Wladimir Araujo Tavares
*Federal University of Ceará http://lia.ufc.br/%7Ewladimir/
Homepage http://lia.ufc.br/%7Ewladimir/ |
Maratonahttps://sites.google.com/site/quixadamaratona/|
*
On Fri, Nov 16, 2012 at 2:46 AM, Pralay Biswas
pralaybiswas2...@gmail.comwrote:
Search for
@Ansum: Notice that the problem does not ask to give a method of making as
many numbers as possible equal, but only what the maximum number is. Here
is an algorithm for achieving an array with the equality numbers I
specified:
1. If the sum of the numbers is a multiple of n, then avg = sum/n
This question has been taken from codeforces.com. Any idea how to solve
this ?
Polycarpus has an array, consisting of *n* integers *a*1, *a*2, ..., *a**n*.
Polycarpus likes it when numbers in an array match. That's why he wants the
array to have as many equal numbers as possible. For that
@Ansum: Polycarpus should start by summing the numbers. If the sum is
divisible by n, then n numbers can be made equal. If the sum is not
divisible by n, then only n-1 numbers can be made equal.
Dave
On Wednesday, November 21, 2012 12:18:54 PM UTC-6, Ansum Baid wrote:
This question has
@Dave: Can you give a little insight on your approach?
On Wed, Nov 21, 2012 at 6:52 PM, Dave dave_and_da...@juno.com wrote:
@Ansum: Polycarpus should start by summing the numbers. If the sum is
divisible by n, then n numbers can be made equal. If the sum is not
divisible by n, then only n-1
@ vishal :let array be {5,2,1,1} == as per u'r algo ={1,2},{1,5} are sets
difference is 3 .. but the sol is {5}{1,1,2} == diff = 1;
On Fri, Nov 16, 2012 at 10:12 AM, vishal chaudhary vishal.cs.b...@gmail.com
wrote:
Hi
Sorry for that as i misinterpreted the question.
for the difference to be
Given an unsorted array, how to divide them into two equal arrays whose
difference of sum is minimum.
--
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
Hi
you can first sort the array which can be done in O(nlogn) complexity if
the number of items in the array is n.
Then using the indexing of arrays you can divide the array into two groups
whose difference is going to be maximum and this can be done in O(1)
complexity.
So the complete algorithm
@ vishal : how can u divide an array into 2 groups whose difference is
maximum in O(1). why max?
solution : http://www.youtube.com/watch?v=GdnpQY2j064
On Fri, Nov 16, 2012 at 9:22 AM, vishal chaudhary
vishal.cs.b...@gmail.comwrote:
Hi
you can first sort the array which can be done in
Hi
Sorry for that as i misinterpreted the question.
for the difference to be minimum, i think(not completely sure) we can first
sort the array
and then we can start putting the elements at even index in the last part
of the array and the odd ones in the starting in the new array
you can do this in
@srikanth
we can use segment trees to get sum of an interval
but there is another condition of sum of distinct numbers only. how can we
take that into account in a segment tree?
On Thursday, 6 September 2012 17:35:59 UTC+5:30, srikanth reddy malipatel
wrote:
post the logic not the code!
BTW
Its better to write an O(n) solution for this problem as the # test cases
are very high and #elements are also very huge..
use visited array for distinct numbers ... space--O(n).. time--O(n)
On Sat, Aug 25, 2012 at 2:39 AM, michael miller
wentworth.miller6...@gmail.com wrote:
Hi,
You are
post the logic not the code!
BTW this problem can be done using segment trees.
http://community.topcoder.com/tc?module=Staticd1=tutorialsd2=lowestCommonAncestor
On Thu, Sep 6, 2012 at 4:51 PM, bharat b bagana.bharatku...@gmail.comwrote:
Its better to write an O(n) solution for this problem
It will be even easier with BIT (Binary Indexed Tree), if you know how to
use it.
--
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
you have to calculate the sum of elements which are less than..that
particular element...this is not the question of calculating cumulative sum
On Wed, Mar 14, 2012 at 11:22 AM, sachin sabbarwal algowithsac...@gmail.com
wrote:
@gaurav popli: how about this one??
findsummat(int arr[],int n)
now i get this!! i thought we have to calculate the sum upto (i-1)th index.
thanx for the clarifiacation.
On Wed, Mar 14, 2012 at 3:07 PM, Dheeraj Sharma dheerajsharma1...@gmail.com
wrote:
you have to calculate the sum of elements which are less than..that
particular element...this is not the
@piyush : sorry dude , didnt get your algo . actually you are using
different array and i get confused which array to be considered when.
On Mon, Mar 12, 2012 at 5:19 PM, Piyush Kapoor pkjee2...@gmail.com wrote:
1)First map the array numbers into the position in which they would be, if
they
@gaurav popli: how about this one??
findsummat(int arr[],int n)
{
int *sum ;
sum =(int*)malloc(sizeof(int)*n);
for(int i=0;in;i++)
sum[i] = 0;
for(int i=0;in;i++)
sum[i] = sum[i-1] + arr[i-1];
//now print the sum array
}
it works very well
plz tell me if anything is wrong
u r right.
On Mon, Mar 12, 2012 at 11:17 AM, atul anand atul.87fri...@gmail.comwrote:
@sanjiv : wont work for this test case :-
{1,5,3,6,2,7,8};
On Mon, Mar 12, 2012 at 10:54 AM, sanjiv yadav sanjiv2009...@gmail.comwrote:
@atul anand- It will still work as follows---
@atul anand : it will work,i can give u the code.
On Mon, Mar 12, 2012 at 11:53 AM, sanjiv yadav sanjiv2009...@gmail.comwrote:
u r right.
On Mon, Mar 12, 2012 at 11:17 AM, atul anand atul.87fri...@gmail.comwrote:
@sanjiv : wont work for this test case :-
{1,5,3,6,2,7,8};
On
@piyush : i dont knw what modification you have made to the BIT to make it
work for this problem .
please provide the code for better understanding or algo will do.
On Mon, Mar 12, 2012 at 3:56 PM, Piyush Kapoor pkjee2...@gmail.com wrote:
@atul anand : it will work,i can give u the code.
On
1)First map the array numbers into the position in which they would be, if
they are sorted,for example
{30,50,10,60,77,88} --- {2,3,1,4,5,6}
2)Now for each number ,find the cumulative frequency of index ( = the
corresponding number in the map - 1).
3)Output the cumulative frequency and increase
@atul...
if its the sum of the elements to the left of a[i] which are smaller the my
approach works w/o any flaw
here's the working code for ithttp://ideone.com/CH7VW
if its the sum of all elements lesser than the element a[i] then this algo
is surely wrong
n we then have to proceed by the
@atul
if its sum of numbers lesser than a[i] in left to i, then still i think it
can be solved in O(nlgn) using Balanced Tree structures
ie: if we use AVL tree, then we just need a little care of how to update
sum stored with rotations
and required ans for ith index must be calculated just after
given an array of size n...
create an array of size n such that ai where ai is the element in the
new array at index location i is equal to sum of all elements in
original array which are smaller than element at posn i...
e.g
ar[]={3,5,1,6,7,8};
ar1[]={0,3,0,9,15,22};
--
You received this
By Augmented BST-
TC-O(n)
On Sun, Mar 11, 2012 at 3:08 PM, Gaurav Popli gpgaurav.n...@gmail.comwrote:
given an array of size n...
create an array of size n such that ai where ai is the element in the
new array at index location i is equal to sum of all elements in
original array which are
u r right payal but
can u expln o(n) time complexity..
On Sun, Mar 11, 2012 at 6:10 PM, payal gupta gpt.pa...@gmail.com wrote:
By Augmented BST-
TC-O(n)
On Sun, Mar 11, 2012 at 3:08 PM, Gaurav Popli gpgaurav.n...@gmail.comwrote:
given an array of size n...
create an array of size n
we can use self balancing BST for this problem to yield the complexity
O(nlogn) ..where every node will contain the sum of the node values on it
left sub tree .. you can check this post..its pretty similar (Method 2)
http://www.geeksforgeeks.org/archives/17235
On Mon, Mar 12, 2012 at 12:58 AM,
@payal : what will be be the structure of the augmented tree , i add 2 to
the given input. so input become.
ar[]={3,5,1,6,7,8,2};
On Sun, Mar 11, 2012 at 11:07 PM, payal gupta gpt.pa...@gmail.com wrote:
the algo vich i thought of is as follows-
struct node{
int data;
struct node
@piyush : i dont think so BIT would work over here , we are not just
reporting cumulative sum tilll index i.
On Mon, Mar 12, 2012 at 12:58 AM, Piyush Kapoor pkjee2...@gmail.com wrote:
This can be done very easily with the help of a Binary Indexed Tree,and it
is very short to code as
@atul anand- It will still work as follows---
(3,0)
/ \(5,0+3)
(1,0) \(6,0+3+5)
\(2,0+1)\(7,0+3+5+6)
\(8,0+3+5+6+7)
here, my logic is that if number is grater
@sanjiv : wont work for this test case :-
{1,5,3,6,2,7,8};
On Mon, Mar 12, 2012 at 10:54 AM, sanjiv yadav sanjiv2009...@gmail.comwrote:
@atul anand- It will still work as follows---
(3,0)
/ \(5,0+3)
(1,0) \(6,0+3+5)
\(2,0+1)
if i am not wrong , solution is given in this thread and with less
complexity :-
http://groups.google.com/group/algogeeks/browse_thread/thread/44dd396b22595142/6632ae276b99d4ad?hl=enlnk=gstq=Array+Problem+%2B+tushar#6632ae276b99d4ad
On Thu, Feb 16, 2012 at 5:54 PM, Devansh Gupta
wellthat will be a different question.in my question i have never
said that value of the element lies between 0 and k moreover...i don't
want the count...i just want the element which is repeated b times...
hope u got the difference.
--
Amol Sharma
Third Year Student
Computer
Given an array of size N having numbers in the range 0 to k where
k=N, preprocess the array inplace and in linear time in such a way
that after preprocessing you should be able to return count of the
input element in O(1).
Please give some idea !!
Thanks..
--
You received this message
if n is less than 10^6 hasing works fine ..and we count in O(1) time only
--
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
@kartik : question says inplace . so using hashing would be violation...
i dont think so it can be done if array is unsorted and with given
restriction
On Wed, Feb 15, 2012 at 10:05 AM, Kartik Sachan kartik.sac...@gmail.comwrote:
if n is less than 10^6 hasing works fine ..and we count in
Yes we can do so in O(n) .
First find the XOR of all unique elements using hash table or some other DS.
Secondly XOR all the elements of the array .which will hav the xor of
elements other thn the element repeated twice.
Now XOR the above two value which will give the answer..
On 11/17/11,
Hi all,
I was creating an algorithm for simple multiplication where * can be
used only for single-single multiplication, I stored the multiplication
results in array.
E.g.
251
*14
---
1004 //c[0][0]=4,c[0][1]=0, c[0][2]=10
251 //c[1][0]=1,c[1][1]=5, c[1][2]=2
@shady: There were no specific constraints. Actually, they didn't expect
any best solution. People who wrote brute force also got shortlisted. Brute
force would be Just picking a number one by one from first row and then
checking other rows for existence of this number. I think it is a O(n^3)
Given an array say A=(4,3,1,2). An array B is formed out of this in
such a way that B[i] = no. of elements in A, occuring on rhs of A[i],
which are less then A[i].
eg.for the A given, B is (3,2,0,0).
Here A of length n only contains elements from 1 to n that too
distinct..
Now the problem is:
1).
all pairs of integers sum upto x.shiuld we take care of duplicates??
--
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
what is the question
???
On Sat, Oct 1, 2011 at 9:08 PM, rahul sharma rahul23111...@gmail.comwrote:
all pairs of integers sum upto x.shiuld we take care of
duplicates??
--
You received this
all integers pairs in array that sum to given value say (k)...i have two sol
for the array that contain unique elements..m asking should i take care of
duplicates or notcoz my logic wont work for duplicates like if i have 0
1 2 3 4 5 6 8 8 if i want all pairs having some 8 ...den it should
given array-
1 0 0 1 1 1 0 1 0 1
for our convenience lets replace 0 by -1
array becomes
1 -1 -1 1 1 1 -1 1 -1 1
take another array count which which represents the sum till that index
sum array becomes
1 0 -1 0 1 2 1 2 1 2 //count array
now make an important
complexity O(n)
extra space O(n)
--
Amol Sharma
Third Year Student
Computer Science and Engineering
MNNIT Allahabad
http://gplus.to/amolsharma99
http://twitter.com/amolsharma99http://in.linkedin.com/pub/amol-sharma/21/79b/507http://youtube.com/amolsharma99
On Thu, Sep 29, 2011 at 11:52 AM,
@Amol +1
On Thu, Sep 29, 2011 at 11:52 AM, Amol Sharma amolsharm...@gmail.comwrote:
given array-
1 0 0 1 1 1 0 1 0 1
for our convenience lets replace 0 by -1
array becomes
1 -1 -1 1 1 1 -1 1 -1 1
take another array count which which represents the sum till that index
sum
O/P should be 00111010 and sub array is exclusive of start index, inclusive
of end index.
Nice solution
On Thu, Sep 29, 2011 at 11:58 AM, UTKARSH SRIVASTAV usrivastav...@gmail.com
wrote:
@Amol +1
On Thu, Sep 29, 2011 at 11:52 AM, Amol Sharma amolsharm...@gmail.comwrote:
given array-
1
@AMOL i want array index i.e i to j that will be max subarry which has equal
no of zero and one's
but i think ur soln is not providing this
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
Impossible to solve in O(n) I suppose
On Thu, Sep 29, 2011 at 12:34 PM, kartik sachan kartik.sac...@gmail.comwrote:
@AMOL i want array index i.e i to j that will be max subarry which has
equal no of zero and one's
but i think ur soln is not providing this
--
You received this message
@kartik...try to implement the algo using pen and paper take 2-3 extra
variables for storing index also along with the variable max.the same
algo will also give you the required subarray indexes along with its
length...
--
Amol Sharma
Third Year Student
Computer Science and Engineering
ok amol i will do it..but i am unable to convience myself that
this algo will give the desire result
--
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
sachan!!amol ke rum par jaakar pooch le.
On Thu, Sep 29, 2011 at 1:10 PM, kartik sachan kartik.sac...@gmail.comwrote:
ok amol i will do it..but i am unable to convience myself that
this algo will give the desire result
--
You received this message because you are subscribed to
Algorithm Kadane
http://www.algorithmist.com/index.php/Kadane%27s_Algorithm
http://www.cs.ucf.edu/~reinhard/classes/cop3503/lectures/AlgAnalysis04.pdf
http://struts2spring.wordpress.com/2009/11/02/finding-the-maximum-contiguous-subsequence-in-a-one-dimensional-array/
Wladimir Araujo Tavares
First,
you need change 0 to -1
Wladimir Araujo Tavares
*Federal University of Ceará http://lia.ufc.br/%7Ewladimir/
Homepage http://lia.ufc.br/%7Ewladimir/ |
Maratonahttps://sites.google.com/site/quixadamaratona/|
*
On Thu, Sep 29, 2011 at 7:35 AM, Wladimir Tavares wladimir...@gmail.comwrote:
Given a binary array ( array containing only 0s and 1s ). You have to
print the sub-array with
maximum number of equal 1s and 0s.
INPUT OUTPUT
1001110101 0011101
complex-O(n)
--
*WITH REGARDS,*
*
suppose an array A[0...n-1] given have to buld another array B[0..n-1] such
that B[i] hold the number of lower or equal values in Right side of A[i]. in
O(nlgn) please post solution . example if A{1,2,0,7,3} so B will be
{1,1,0,1,0} .
--
You received this message because you are subscribed to
you can use mergesort technique, segment tree, binary index tree or BST
--
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
Write a method fill up an array of size n - and returns the array to the
caller - with the following conditions
1. the numbers shud be between 0 to n-1
2. no repeated numbers
3. the method should have a deterministic time to fill the arrays
4. arrays returned from the method should have
=Take a function rand() which returns value between [0, 1) uniformly or use
function rand(n) = n*rand() which return value between 0- (n-1) using
uniform probability distribution.
=Now create a array A[0..n-1] = [0..n-1]
now rake an array R.
k = n;
for(i = 0; i n; i++){
a = rand(k);
take a subset from the array, if the average is equal then output the
result.
backtracing can do this.
the time complexity seems not low, any good idea~~?
2011/8/27 sukhmeet singh sukhmeet2...@gmail.com
how to divide an integer array into 2 sub-arrays and make their averages
equal?
array is
Algo:
1. Sort the array
2. modify binary search on the set comparing average of both the set.
3. if aveage (start, mid) average (mid , end) then go to left sub
set else right subset.
This could lead to solution in o(nlogn) time. Please comment futher!!
Cheers,
Ankit Sinha
On Sat, Aug 27,
@Ankit: Ur solution has some flaws I think. Ur solution assumes that we r
dividing the sorted array into 2 halves, but the question says: divide an
integer array into 2 sub-arrays and make their averages equal. Take some
test case and apply ur solution to it.
We cud do this problem in the
how to divide an integer array into 2 sub-arrays and make their averages
equal?
array is unsorted and we can also take any numbers and the numbers in the
array need not be contiguous in the original array.
how many total such array's are possible. Output them
--
You received this message because
while(a)
(
a=(a-1)
count++
)
counts number of 1s in number 'a'..
Loop can be breaken if count exceeds 16..
On 8/21/11, himanshu kansal himanshukansal...@gmail.com wrote:
problem: There is an array containing integers.
for every bit in the integer,you have to print a 1 if no of 1s
Similary as we are counting set bits count 0's nd cmpare nd set 1 if
coutn(1)count(0) for each integer in array
On Sun, Aug 21, 2011 at 1:44 PM, Sanjay Rajpal srn...@gmail.com wrote:
@Dheeraj : I think u should review the problem again.
What u have posted is a way to find no. of set bits in a
yeah i took it in the another way..i ll post it v soon
On 8/21/11, himanshu kansal himanshukansal...@gmail.com wrote:
problem: There is an array containing integers.
for every bit in the integer,you have to print a 1 if no of 1s
corresponding to that bit is more than no of 0s corresponding
let n be the no.of integers in the array :
int i=1,a;
int zero,one;
for(int a=1;a=32;a++)
{
zero=0;
one=0;
for(int j=0;jn;j++)
{
if(a[j] i)
{
one++;
}
else
{
This problem can be reduced if we are taking whole 32 bits...
Mean left most all 0's bits are also including
then if number is less than 65535 (2^16-1) then make it 0
as 16 bits are at least zero in this case
On Sun, Aug 21, 2011 at 2:19 PM, Sanjay Rajpal srn...@gmail.com wrote:
let n be
yeah bt..when we talk abt the complexity..we consider abt the worst case
On 8/21/11, himanshu kansal himanshukansal...@gmail.com wrote:
problem: There is an array containing integers.
for every bit in the integer,you have to print a 1 if no of 1s
corresponding to that bit is more than no
when u xor nos with odd number of times we will get back the same no.only
even occurences will give 0.question is to find the no with even
occurence.how will you find that no?
On Tue, Aug 16, 2011 at 1:41 PM, MAC macatad...@gmail.com wrote:
Given an array of integers. Each number in the array
Given an array of integers. Each number in the array repeats ODD number of
times, but only 1 number repeated for EVEN number of times. Find that
number.
--
thanks
--mac
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group,
One easier thing would be to use a map to solve this.
On Tue, Aug 16, 2011 at 1:41 PM, MAC macatad...@gmail.com wrote:
Given an array of integers. Each number in the array repeats ODD number of
times, but only 1 number repeated for EVEN number of times. Find that
number.
--
thanks
@sukran:
If you were asking for the map based solution
space and time complexity would be o(n).
On Tue, Aug 16, 2011 at 2:34 PM, sukran dhawan sukrandha...@gmail.comwrote:
what is the complexity in which it has been done ?
On Tue, Aug 16, 2011 at 1:41 PM, MAC macatad...@gmail.com wrote:
The question needed o(1) space and o(n) time ... o(n) map approach is
obviously fine but space is taken up ...
On Tue, Aug 16, 2011 at 2:38 PM, Raghavan its...@gmail.com wrote:
@sukran:
If you were asking for the map based solution
space and time complexity would be o(n).
On Tue, Aug
- Sort the array - o(log n) based on the sorting strategy might be radix
sort
- check the numbers count have a counter o(1) space and again o(n) time
- changing from one number to other check counter%2 == 0 if so then we
get answer
So consolidated time would be o(n) and space is
i think XOR operator should be used to solve question.
Given the integers in the array A: n1,n2...nk,
we can do this recursively:
XOR all the integers in A, assume the result is F = n1^n2^...^nk,
F must not be 0.
for i-th bit in F from rightmost to left most:
if the i-th bit is 1, halve A
int lol=2; // total lol's encountered upto now
lol++;
On Mon, Aug 15, 2011 at 12:41 AM, aditi garg aditi.garg.6...@gmail.comwrote:
lol
On Mon, Aug 15, 2011 at 12:40 AM, aditya kumar
aditya.kumar130...@gmail.com wrote:
@aditi : sry i dint realise that n log n .:P
On Mon, Aug 15, 2011
On 15 August 2011 21:07, sagar pareek sagarpar...@gmail.com wrote:
int lol=2; // total lol's encountered upto now
lol++;
it is a programming mistake as you have indicated the value of the important
variable constant lol to 2 and then you have incremented it. :P
On Mon, Aug 15, 2011 at
any O(nlogn) solution?
--
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/-/7Q8DHLIlbDoJ.
To post to this group, send email to algogeeks@googlegroups.com.
To
given two arrays : with all distinct elements but one element in common.
Find the common element in optimal time.
--
*MOHIT VERMA*
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
meaning ? what is a common element ? example ???
On Sun, Aug 14, 2011 at 6:37 PM, mohit verma mohit89m...@gmail.com wrote:
given two arrays : with all distinct elements but one element in common.
Find the common element in optimal time.
--
example:
array 1 :: 1 2 3 4 5 6 7 8 9 10 15
array 2:: 23 34 56 13 15 57 432 348
On Sun, Aug 14, 2011 at 6:44 PM, shady sinv...@gmail.com wrote:
meaning ? what is a common element ? example ???
On Sun, Aug 14, 2011 at 6:37 PM, mohit verma mohit89m...@gmail.comwrote:
how about binary search of each element from array 1 on array 2?
overall complexity : O(nlogn)
On 14 August 2011 18:46, mohit verma mohit89m...@gmail.com wrote:
example:
array 1 :: 1 2 3 4 5 6 7 8 9 10 15
array 2:: 23 34 56 13 15 57 432 348
On Sun, Aug 14, 2011 at 6:44 PM, shady
Hashing
O(n+m)
On Sun, Aug 14, 2011 at 6:48 PM, Dipankar Patro dip10c...@gmail.com wrote:
how about binary search of each element from array 1 on array 2?
overall complexity : O(nlogn)
On 14 August 2011 18:46, mohit verma mohit89m...@gmail.com wrote:
example:
array 1 :: 1 2 3 4 5 6 7 8
@ Sagar:
What if extra space in not allowed?
I think then we have to use the binary search method...
On 14 August 2011 18:50, sagar pareek sagarpar...@gmail.com wrote:
Hashing
O(n+m)
On Sun, Aug 14, 2011 at 6:48 PM, Dipankar Patro dip10c...@gmail.comwrote:
how about binary search of each
@sagar suppose numbers are very large( 10^9) , how will you hash then ?
can you please state the hashing function in this case
On Sun, Aug 14, 2011 at 6:50 PM, sagar pareek sagarpar...@gmail.com wrote:
Hashing
O(n+m)
On Sun, Aug 14, 2011 at 6:48 PM, Dipankar Patro dip10c...@gmail.comwrote:
i feel binary search idea is the best
guys i am having problem in finding out complexity...here is my
solution to the above problem...whats the complexity...
sort the 2 arraysa and b
l=0,i=0,flag=0;
while(a[i]b[0]) // to start comparing from the value that is
slightly greater than the
doesnt matter Order will be (nlogn)
where n is max(elements in first set, elements in 2nd set)
PS : dont submit codes from next time
On Sun, Aug 14, 2011 at 7:43 PM, Nikhil Veliath nve...@gmail.com wrote:
i feel binary search idea is the best
guys i am having problem in finding out
Given an ordered array A[1…n] with numbers in strictly increasing
order. Find a ‘j’ such that A [j]=j or -1 if no such number exist in
o (log n).
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to
already discussed... binary search :)
On Mon, Aug 15, 2011 at 12:26 AM, aditi garg aditi.garg.6...@gmail.comwrote:
Given an ordered array A[1…n] with numbers in strictly increasing
order. Find a ‘j’ such that A [j]=j or -1 if no such number exist in
o (log n).
--
You received this message
just my 2 cents in d binary search, replacing key with mid, ie
if(a[mid] mid)
check lower half
else upper half
should work??
On Mon, Aug 15, 2011 at 12:26 AM, aditi garg aditi.garg.6...@gmail.comwrote:
Given an ordered array A[1…n] with numbers in strictly increasing
order. Find a ‘j’
1 - 100 of 256 matches
Mail list logo